Quantcast C/C++ Puzzles | Prog2impress.com
Sorry! Site is Under Construction, Link Doesn't Exist.
Logo
C and C++ Puzzles. Test and Improve Your Level of Programming Skills.

Dear visitor, Thanks for your interest in Prog2impress.com. I always have an interest towards interview questions and puzzles, especially the programming ones. Here are some of the trivial C and C++ puzzles that I have come across. In this page, you will find a list of interesting C++ programming questions/puzzles, Some companies certainly ask for these puzzles. Answers are not provided, i'll leave it for you to find the best one. Please feel free to contact us through our mail id prog2impress@gmail.com if you need any help in solving the problems.

"We found that most of the visitors feel these puzzles as simple one. We started this one as simple one only to attract more beginners. We will update these puzzles more regularly in coming weeks and decided to include difficult ones for qiuck witted guys, so please keep visiting reqularly."




C/C++ Projects with Source Codes Contributed By Jag

1. Hotel Reservation System.

2. Library Management System.

3. Chess Game Developed in C++.

4. Bricks Game in C/C++.

1. what is the output? Definitely the output is not what you think! so think more..

main()
{
int i = 300;
char *ptr = &i;
*++ptr = 2;
printf("%d",i);
getch();
}

2. Fill find_addr() so that it finds the address of variable i and j in main(). main() should't be touched

#include<stdio.h>
#include<conio.h>
find_addr()
{
/*fill your code here*/
}
void main()
{
int i,j;
clrscr();
find_addr();
getch();
}

3. what is the output of the following code if array name starts with 65486.

void main()
{
int num[] = {10,11,12,13};
printf("%u %u",num,&num);
}

4.what is the output of the following code specify if there is any error.

main( )
{
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);
}

5. what is the output of the following code specify if there is any error.

main ( )
{
static char *s[ ] = {“black”, “white”, “yellow”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(“%s”,*--*++p + 3);
}

6. what is the output of the following code specify if there is any error.

main()
{
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n];
for(i=0; i
{
printf(“%s\n”,x);
x++;
}
}

7. Specify the reason for the error?

main()
{
int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
}

8. An runtime error occurs while executing this prog why?

main()
{
main();
}

9. will the program compile if there is any error specify and specify the reason?

main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}

10. what will be the output of the program?

#define FALSE -1
#define TRUE 1
#define NULL 0
main()
{
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}

11. what will be the output of the program?

main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}

12. Will the code compile if there is any error specify the reason?

#define max 5
#define int arr1[max]
main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
arr2 name="name";
printf("%d %s",list[0],name);
}

13. What will be the output of the program?

int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}

14.What will be the output of the program?

#include
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}

15. What will be output of the following program ?

void main()
{
int quo = 5, a;
do
{
a /= quo;
} while (quo --);
printf ("%d\n", a);
}

16. Write a program to swap two integers without using any temporary variable. there are few ways to do this write all those.

17. What will be the output of this program

main()
{
int a=3, b = 5;
printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);
printf(&a["WHAT%c%c%c %c%c %c !\n"], 1["this"], 2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);
}

18. What is the output of this program if any ERROR specify?

void main()
{
char ch[]={'A','B','I','D','a','f','t','k'},*ptr;
clrscr();
ptr=ch;
*++ptr=*(ch+2);
printf("c=%c",*ptr+4);
getch();
}

19. Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

20. Write a program to print the series 2 power x, where x >= 0 ( 1, 2, 4, 8, 16, .... ) without using C math library and arithmatic operators ( ie. *, /, +, - and math.h are not allowed)

21.What's the "condition" so that the following code snippet prints both HelloWorld !

if  "condition"
printf ("Hello");
else
printf("World");

22.what is the error if not specify the output?

f(a,b)
int a,b;
{
return (a=(a==b));
}
main()
{
int process(),f();
clrscr();
printf("the value of process :%d\n",process(f,7,4));
getch();
}
process(hai,val1,val2)
int (*hai)();
int val1,val2;
{
return ((*hai)(val1,val2));
}

23. what is the output of the program. If there is any error what is the reason it occur and what is the solution?

void main()
{
struct stud
{
char name[20];
int age;
float salary;
};
struct stud s[10];
int i;
clrscr();
for(i=0; i<=3 ; i++)
scanf("%s %f %d", s[i].name,&s[i].salary, &s[i].age);
getch();
}

24.Write a C program to find if the given number is a power of 2 using a single expression.

25. what is output of the program if any error specify?

void main()
{
int i,j;
int add;
struct st
{
int x;
char ch='a';
}s;
s.ch='a';
i=7;
j=20;
i=i+j*j;
s.x=i+(s.ch);
}

Popular Links


BUY THE BEST

Top Pages