You are on page 1of 8

‘C’ & ‘C’ only Sona Placement & Training Cell

1. C Fundamentals
Week : 1 Duration : 60 mins

1. What number of digits that can be accurately stored in a float ?


a) 6 b) 38 c) An unlimited number

2. Which of the following is evaluated first?


a) && b) || c) !

3. What does 7/9*9 equal?


a) 1 b) 0.08642 c) 0

4. Which is not valid in C ?


a) class aClass{public:int x;}; b) /* A comment */
c) char x=12;

5. Which of the following is not a valid declaration for main() ?


a) int main() b) int main(intargc,char*argv[])
c) They both work

6. What is the output of ?


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);
}

7. Predict the output of the following code:


main()
{ printf(“%x”,-1<<4);
}

8.What is the output of the following code?


main()
{ int c=- -2;
printf(“c=%d”,c);
}

1
‘C’ & ‘C’ only Sona Placement & Training Cell

9. Evaluate the following: 22%5


a) 2 b) 4 c) 0

10. In int main(int argc, char *argv[]) what is argv[0] usually going to be?
a) The first argument passed into the program b) The program name
c) You can’t define main like that

11. What is the output of the following code?


#define int char
main()
{ int i=65;
printf(“sizeof(i)=%d”,sizeof(i));
}

12. What is the output of the following code?


main()
{ int i=10;
i=!i>14;
printf (“i=%d”,i);
}

13. What is the output of the following code?


main()
{ printf(“\nab”);
printf(“\bsi”);
printf(“\rha”);
}

14. What is the output of the following code?


main()
{ clrscr();
}
clrscr();

15. What is the output of the following code?


enum colors {BLACK,BLUE,GREEN}
main()
{ printf(“%d..%d..%d”,BLACK,BLUE,GREEN);
return(1);
}

2
‘C’ & ‘C’ only Sona Placement & Training Cell

16. Predict the output of the following code:


main()
{ int i=400,j=300;
printf(“%d..%d”);
}

17. What is the output of the following code?


main()
{ char not;
not=!2;
printf(“%d”,not);
}

18. Predict the output of the following code:


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

19. Predict the output of the following code:


main()
{ int i=-1;
-i;
printf(“i = %d, -i = %d \n”,i,-i);
}

20.What is the output of the following code?


#include<stdio.h>
main()
{ const int i=4;
float j;
j = ++i;
printf(“%d %f”, i,++j);
}

3
‘C’ & ‘C’ only Sona Placement & Training Cell

21. Predict the output of the following code:


#include<stdio.h>
main()
{ register i=5;
char j[]= “hello”;
printf(“%s %d”,j,i);
}

22. Predict the output of the following code:


main()
{ int i=5,j=6,z;
printf(“%d”,i+++j);
}

23.What is the output of the following code?


main()
{ int i=5,j=10;
i=i&=j&&10;
printf(“%d %d”,i,j); }

24.What is the output of the following code?


main()
{ int i=4,j=7;
j = j || i++ && printf(“YOU CAN”);
printf(“%d %d”, i, j);
}

25. What is the output of the following code?


main()
{ register int a=2;
printf(“Address of a = %d”,&a);
printf(“Value of a = %d”,a);
}

26. What is the output of the following code?


main()
{ extern i;
printf(“%d\n”,i);
{ int i=20;
printf(“%d\n”,i); }
}

4
‘C’ & ‘C’ only Sona Placement & Training Cell

27.What is the output of the following code?


void main()
{ char ch;
for(ch=0;ch<=127;ch++)
printf(“%c %d \n“, ch, ch);
}

28. Printf can be implemented by using __________ list.

29.What is the output of the following code?


main()
{ int i=_l_abc(10);
printf(“%d\n”,--i);
}
int _l_abc(int i)
{ return(i++); }

30. Find the output of the following code?


int i;
main()
{ int t;
for ( t=4;scanf(“%d”,&i)-t;printf(“%d\n”,i))
printf(“%d--”,t--);
}
// If the inputs are 0,1,2,3 find the o/p

1. Assignment

31. Find the output of the following code?


main()
{ int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf(“hello”);
}

32. Find the output of the following code?


main()
{ unsigned int i;
for(i=1;i>-2;i--)
printf(“c aptitude”);
}

5
‘C’ & ‘C’ only Sona Placement & Training Cell

33. Find the output of the following code?


main()
{ int i =0;j=0;
if(i && j++)
printf(“%d..%d”,i++,j);
printf(“%d..%d,i,j);
}

34. Find the output of the following code?


void main()
{ int i=i++,j=j++,k=k++;
printf(“%d%d%d”,i,j,k);
}

35. Predict the output of the following code:


void main()
{ static int i=i++, j=j++, k=k++;
printf(“i = %d j = %d k = %d”, i, j, k);
}

36. Predict the output of the following code:


main()
{ int a[10];
printf(“%d”,*a+1-*a+3);
}

37. Predict the output of the following code:


main()
{ float f=5,g=10;
enum{i=10,j=20,k=50};
printf(“%d\n”,++k);
printf(“%f\n”,f<<2);
printf(“%lf\n”,f%g);
printf(“%lf\n”,fmod(f,g));
}

38.What is the output for the program given below ?


typedef enum errorType{warning, error, exception,}error;
main()
{ error g1;
g1=1;
printf(“%d”,g1); }

6
‘C’ & ‘C’ only Sona Placement & Training Cell

39. What is the output of the following code?


typedef struct error{int warning, error, exception;}error;
main()
{ error g1;
g1.error =1;
printf(“%d”,g1.error);
}

40. What is the output of the following code?


main()
{ int i=5;
printf(“%d”,++i++);
}

41. What is the output of the following code?


main()
{ int i=5;
printf(“%d”,i=++i ==6);
}

42. What is the output of the following code?


main()
{
int i=10,j=20;
j = i, j?(i,j)?i:j:j;
printf(“%d %d”,i,j);
}

43. What is the output of the following code?


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

44. What is the output of the following code?


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

7
‘C’ & ‘C’ only Sona Placement & Training Cell

45. What is the output of the following code?


main()
{ int i=-1;
+i;
printf(“i = %d, +i = %d \n”,i,+i);
}

46. What is the output of the following code?


main()
{ extern int i;
i=20;
printf(“%d”,i);
}

47. What is the output of the following code?


main()
{ int i;
printf(“%d”,scanf(“%d”,&i)); // value 10 is given as input here
}

48. What is the output of the following code?


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

49. What is the output of the following code?


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

50. What is the output of the following code:


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