0% found this document useful (0 votes)
78 views

C Questions For Cse

The document contains 50 C programming questions and code snippets. It asks to predict the output or errors for each code snippet. The snippets cover a wide range of C concepts like loops, arrays, pointers, structures, typecasting, macros, etc.

Uploaded by

SiriSantosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

C Questions For Cse

The document contains 50 C programming questions and code snippets. It asks to predict the output or errors for each code snippet. The snippets cover a wide range of C concepts like loops, arrays, pointers, structures, typecasting, macros, etc.

Uploaded by

SiriSantosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

C Questions

Predict the output or error(s) for the following:


2.

3.

4.

5.

6.

7.

8.

9.

main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
main()
{ float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
main()
{ static int var = 5;
printf("%d ",var--);
}
main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}
main()
{ extern int i;
i=20;
printf("%d",i); }
main()
{ int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);}
main()
{ char *p;
printf("%d %d ",sizeof(*p),sizeof(p));}

main()
{ int i=3;
switch(i)
{ default:printf("zero");
case 1: printf("one"); break;
case 2:printf("two");
break;
case 3: printf("three"); break; }
}
10. main()
{ printf("%x",-1<<4);}
11. main() {
char string[]="Hello World";
display(string); }
void display(char *string)
{
printf("%s",string); }
12. main()
{ int c=- -2;
printf("c=%d",c);
}
13. #define int char
main()
{ int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
14. main( ){ int i=10;
i=!i>14; Printf ("i=%d",i);
}

15. #include<stdio.h>
main()
{ char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p; str1=s;
printf("%d",++*p + ++*str1-32);
}
16. #include<stdio.h>
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);
}
17. #include<stdio.h>
main()
{ struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
18. #include<stdio.h>
main()
{ struct xx
{ int x;
struct yy {
char s;
struct xx *p;
}; struct yy *q;
}; }
19. main()
{ printf("\nab");
printf("\bsi");
printf("\rha");
}
20. main()
{int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
21. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i); }

22.

main()

{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}
23. #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
24. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr()); }
25. main()
{
printf("%p",main); }
26)
main()
{ clrscr(); }
clrscr();
28)

enum colors {BLACK,BLUE,GREEN}

29)

30)

31)

32)

33)

34)

main()
{
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1); }
void main()
{
char far *farther,*farthest;
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
main()
{
int i=400,j=300;
printf("%d..%d");
}
main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}
void main()
{
int i=5;
printf("%d",i++ + ++i);
}

35)

void main()
{
int i=5;
printf("%d",i+++++i);
}

36)

#include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}}
main()
{ int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}

37)

38)

#define f(g,g2) g##g2


main()
{
int var12=100;

39)

40)

41)

printf("%d",f(var,12));
}
main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
#include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
#include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}

42)

#include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}

43)

main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}

44)

main()
{
printf("%d", out);
}
int out=100;

45)

main()
{
extern out;
printf("%d", out);
}
int out=100;

46)

main()
{
show();
}
void show()
{
printf("I'm the greatest");
}

47)

main( )

{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(%u %u %u %d \n,a,*a,**a,***a);
printf(%u %u %u %d \n,a+1,*a+1,**a+1,***a+1);
}
48)

main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{
printf(%d ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf(%d ,*p);
p++;
}
}

49)

main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
}

50)

main( )
{
char *q;
int j;
for (j=0; j<3; j++) scanf(%s ,(q+j));
for (j=0; j<3; j++) printf(%c ,*(q+j));
for (j=0; j<3; j++) printf(%s ,(q+j));
}

You might also like