Page 1 of 3123> Show 40 post(s) from this thread on one page

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Multiple Choice Questions in C (Answers not given) (http://www.go4expert.com/articles/multiple-choice-questions-c-answers-t2791/)

 sibu 31Jan2007 20:27

Multiple Choice Questions in C (Answers not given)

1.
Code: C

`#include<stdio.h>#include<conio.h>main(){    int a[3],i;    for(i=0;i<3;i++)    a[i]=i++;    for(i=0;i<3;i++)    printf("\t%d",a[i]);}`

a. 0 Garbage Value 2
b. 0 1 2
c. 1 2 3
d. None of the above

2.
Code: C

`void main(){    int a = 123, b = 456;    a ^= b ^= a ^= b;    printf("%d\t%d",a,b);}`

a. 123 456
b. 123 123
c. 456 456
d. 456 123

3.
Code: C

`void main(){    int a=5,b=4,c=10;    *((a>b) ? &a : &b) = (a+b>c);    printf("%d\t%d",a,b);}`

a. Syntax Error
b. Fatal Error
c. 0 4
d. System Hangs

4.
Code: C

`void f(int *ip){    static int dummy = 5;    ip = &dummy;    printf("%u\n",ip);}void main(){    int *ip;    f(ip);    printf("%u",ip);}`

a. Some Values
b. 0 Some Value
c. Error
c. None of the Above

5.
Code: C

`void main(){    int realarray[2]={1,2};    int *array = &realarray[-1];    int i;    for(i=0;i<2;i++)    {        printf("\t%d",*array);        array++;    }}`

a. Error
b. Garbage Value 1
b. 0 1
d. 1 2

6.
Code: C

`#define Str(x) #x#define Xstr(x) Str(x)#define OP plusvoid main(){    char *opname = Xstr(OP);    printf("%s",opname);}`

a. plus
b. Compilation Error
c. Runtime Error
d. Linker Error

7.
Code: C

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

a. 20 20
b. Garbage Value 20
c. 0 20
d. Linker Error

8.
Code: C

`int main(){    int a=500,b=100,c=30,d=40,e=19;    a+=b-=c*=d/=e%=5;    printf("\n%d %d %d %d %d",a,b,c,d,e);}`

a. 0 -200 300 10 4
b. 300 -200 300 10 4
c. -200 300 10 4 0
d. 100 -200 300 4 10

9.
Code: C

`void main(){    int a=1,b=2,c=3,d=4;    printf("%d",!a?b?!c:!d:a);}`

a. 1
b. 0
c. No Output
d. Error

10.
Code: C

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

a. Program Hangs
b. No Output
c. 6 4 2
d. 5 2

11.
What will be the output of the following program :
Code: C

`void main(){    int val=1234;    int* ptr=&val;    printf("%d %d",val,*ptr++);}`

a. 1234 1234
b. 1235 1235
c. 1234 1235
d. 1235 1234

12.
What will be the output of the following program :
Code: C

`void main(){    int i;    float a[5];    for (i=0; i<5; i++)        a[i] = (printf, ("%d",i/10.0));    for (i=0; i<5; i++)        printf("%.1f ",a[i]);}`

a. Compile-Time Error
b. 0.0 0.0 0.0 0.0 0.0
c. 0.0 0.1 0.2 0.3 0.4
d. 1.0 1.0 1.0 1.0 1.0

13.
What will be the output of the following program :
Code: C

`void func()    {      printf("Testing...Done\n");    }    void main()    {      func;      func();    }`

a. Compile-Time Error
b. Testing...Done
c. Testing...Done
Testing...Done
d. None of these

14.
A signed int bitfield 1-bit wide can only hold the values

a. 0 and 1
b. 0 and -1
c. 0, 1 and -1
d. None of these

15.
Code: C

`void main()    {       int _;       _=100;       printf("%d",_);    }`

a. 100
b. Linker Error
c. Run Time Error
d. Compiler Error

16.
Code: C

`void main()    {      int choice=2;      switch(choice)      {         default:            printf("Default1");         case 1:            printf("Case1");            break;         default:            printf("Default2");      }     }`

a. Compile-Time Error
b. Default1Case1
c. Default2
d. Default1

17.
Code: C

`#define big(a,b) a > b ? a : b    #define swap(a,b) temp=a; a=b; b=temp;    void main()    {       int a=3,b=5,temp=0;       if ((3+big(a,b)) > b)          swap(a,b);       printf("%d %d",a,b);    }`

a. 3 0
b. 5 3
c. 3 5
d. 5 0

18. Evaluate the following:
Code: C

`int fn(int v){    if(v==1 || v==0)        return 1;    if(v%2==0)        return fn(v/2)+2;    else        return fn(v-1)+3;}for fn(7);`

a. 10
b. 11
c. 1
d. 0

19. What does the line containing "break;" do in the following code?
Code: C

`void afunction(){    if(1)    {        break;        afunction();         printf("Error");     }}`

a. Breaks out of the if statement
b. Exits the function
c. Compiler error
d. Nothing

20. What does the following code do?
Code: C

`void afunction(int *x){    x=new int;    *x=12;}int main(){    int v=10;    afunction(&v);    printf(“%d”,v);}`

a. Outputs 12
b. Outputs 10
c. Outputs the address of v
d. No Output

21. If a machine architecture assigns 4 bytes to store the address of a variable, what should be the output of the program stated below?

Code: C

`main(){    char *p;    printf(“%d %d”, sizeof(char *p), sizeof(*p));}`

a. 1 4
b. 4 4
c. 4 1
d. 1 1

22. What would be the output of the following?

Code: C

`main(){ int a=10,b; a>=5?b=100:b=200; printf("\n%d",b);}`

a. 100
b. 200
c. Compiler Error
d. None of the above

23. What would be the output of the following?

Code: C

`main() {  int i=4;  switch(i)   {     default: printf(“A”);     case 1: printf(“B”);          break;     case 2: printf(“C”);          break;     case 3: printf(“D”);           break;    } }`

a. A
b. B
c. All the above
d. None of the above

24. What would be the output of the following?

Code: C

`#define SQR(x) x*xmain() {   int a,b=3;   a=SQR(b+2);   printf(“%d”,a); }`

a. 25
b. 11
c. Error
d. Garbage Value

25. If the following program(myprog) is run from the command line as myprog mon tue wed thu, what would the output?

Code: C

`main(int argc, char *argv[]) {  while(--argc>0)   printf(“%s”, *++argv); }`

a. myprog mon tue wed thu
b. mon tue wed thu
c. myprog tue thu
d. tue thu

26. What is the type of variable f2 and p2 in the following declaration?

#define floatptr float *
#define int * intptr

floatptr f1,f2;
intptr p1,p2;

a. float, int pointer
b. float pointer, int pointer
c. float, int
d. float pointer, int

27. What would be the output of the following?

Code: C

`main() {   const int x;   x=128;   printf(“%d”,x); }`

a. 128
b. 0
c. Garbage Value
d. Error

28. If the following program(myprog) is run from the command line as myprog fri tue sun, what would the output?

Code: C

`main(int argc, char *argv[]) {  printf(“%c”,**++argv); }`

a. m
b. f
c. s
d. None of the above

29. What would be the output of the following?

Code: C

`void main() {  int z,x=5,y=-10,a=4,b=2;  z=x++ - --y *b/a;  printf("\n%d",z); }`

a. 5
b. 12
c. 10
d. 11

30. What would be the output of the following?
Code: C

`char *fun(char *ptr) {  ptr+=3;  return(ptr); }void main() {  char *x,*y;  x="Hello";  y=fun(x);  printf("\n%s",y); }`

a. Hello
b. lo
c. llo
d. Error

31.
Code: C

`struct node *nptr,*sptr; /*pointers for linked list*/for(nptr=sptr;nptr;nptr=nptr->next) {   free(nptr); }`

releases memory from a linked list. Which of the following accurately describes how it will work?

a. It will work correctly since the for loop covers the entire list.
b. It may fail since each node “nptr” is freed before its next address can be accessed.
c. This is invalid syntax for freeing memory
d. The loop will never end

32. In C, what is the difference between a declaration and definition of a variable?

a. Both can occur multiple times, but a declaration must occur first.
b. Both can occur multiple times, but a definition must occur first.
c. A definition occurs once, but declaration may occur many times.
d. A declaration occurs once, but definition may occur many times.

33. What would be the output of the following?

Code: C

`void main(){    int a=10,b;    b=a++ + ++a;    printf("\n%d %d %d %d",b,a++,a,++a);}`

a. 22 10 11 13
b. 22 11 11 11
c. 22 10 11 13
d. 22 13 13 13

34. sizeof is an ________________

a. int
b. unsigned int
c. long int
d. Anyone of the above

35. . and -> are __________ operators.

a. Binary
b. Unary
c. Ternary
d. None of the above

36. What would be the output of the following?
Code: C

`main(){    int val1=1234;    int val2=01234;    printf("%d %d",val1,val2);}`

a. 1234 1234
b. 1234 01234
c. 1234 668
d. 1234 688

37. chmod() function is defined in which header file?

a. assert.h
b. dos.h
c. io.h
d. Mem.h

38. The header file which includes stdarg.h is_____________

a. assert.h
b. dos.h
c. io.h
d. Mem.h

39. _______________ is a direct interface to the DOS call 0x44

a. ioctl
b. ios
c. dup
d. tell

40. What would be the output of the following?
Code: C

`main(){    int i=strlen("Blue")+strlen("Purple")/strlen("Red")-strlen("Green");    printf("\n%d",i);}`

a. 0
b. 3
c. 2
d. 1

41. What would be the output of the following?
Code: C

`void main(){    int i=7;    printf("\n%old %old %old %old",i,i++,i--,i++);    getch();}`

a. old old old old
b. 7ld 8ld 7ld 8ld
c. 10ld 7ld 10ld 7ld
d. Error

42. longjmp cannot pass the value ________.

a. -1
b. 0
c. 1
d. 2

43. Scope of a global variable which is declared as __________ is within the file.

a. static
b. extern
c. register
d. function argument

44. What value is returned by abort function?

a. Depends on the parameter passed
b. 3
c. Depends on the Operating System
d. 0

45. What would be the output of the following?
Code: C

`main(){    int i,j;    for(i=0;;i++)    for(j=0;;j++)    if(j>100) break;    printf("%d%d",i,j);}`

a. System Hangs
b. 100 100
c. 0 100
d. 1 100

46. What would be the output of the following?

Code: C

`main(){    const int x=5;    int *ptr;    ptr=&x;    *ptr=10;    printf("%d",x);}`

a. 5
b. 10
c. Error
d. Garbage Value

47. What would the output of the following?

Code: C

`main() {  int y,x=5;  y=++x - ++x;  printf("\n%d%d",x,y); }`

a. 7 1
b. 7 -1
c. 7 0
d. 5 1

48. What would be the output of the following?
Code: C

`main(){ char *str = "\eMissi\0ssippi\z"; printf("%s",str);}`

a. eMissi
b. eMissi ssippiz
c. Mississippi
d. Missi

49. Format specifier %p is used for _______________

a. Print the address contained in a pointer variable
b. Peak a value at a location
c. Print the address in segment: offset notation
d. Same as %d

50. What would be the output of the following program?
Code: C

`main() {  char *str,*str1="I Love You";  str=malloc(strlen(str1));  strcpy(str,str1);  printf("%s",str);  free(str); }`

a. free() fails
b. I Love You
c. malloc() fails
d. strcpy() fails

51. What would be the output of the following?
Code: C

`main() {  char a[5][5],flag;  a[0][0] = 'A';  flag=((a==*a)&&(*a==a[0]));  printf("\n%d",flag); }`

a. 1
b. 0
c. Error
d. No output

52. What would be the output of the following?
Code: C

`main(){ static int a[]={0,1,2,3,4}; static int *p[]={a,a+1,a+2,a+3,a+4}; int **ptr; 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); getch();}`

a.
1 0 1
1 0 2
1 0 2
b.
0 1 1
1 1 1
1 1 1
c.
1 2 3
2 2 3
2 3 3
d.
1 0 1
1 0 1
1 1 2

53. What would be the output of the following?
Code: C

`main(){    int i=0;    for(i=0;i<20;i++)    {        switch(i)        {            case 0: i+=5;            case 1: i+=2;            case 5: i+=5;            default: i+=4;            break;        }        printf("\t%d",i);    }}`

a. 0 5 9 13 17
b. 5 9 13 17
c. 12 17 22
d. 16 21

54. What would be the output of the following?
Code: C

`#define CUBE(x) x*x*xmain() {  int a,b=3;  a=CUBE(b++);  printf("\n%d\t%d",a,b); }`

a. 64 4
b. 27 4
c. 27 6
d. 64 6

55. What would be the output of the following?

Code: C

`#define square(b) b*bmain(){ int a; a=64/square(4); printf("\n%d",a);}`

a. 64
b. 4
c. 16
d. None of the above

56. What would be the output of the following?

Code: C

`#define f(g,g2) g##g2main(){ int var12=100; printf(“%d”,f(var,12));}`

a. Invalid Pragma
b. 12
c. 100
d. Compiler Error

57. What would be the output of the following?
Code: C

`main(){    int x = 5;     int y = 10;     double z;     z = (double) (5 / 10);     printf("z = %.2f\n", z); }`

a. 1.00
b. 0.50
c. 0.00
d. -0.50

58. Which one of the following describes the chief difference between a structure and a union?

a. The fields of a structure overlap each other in memory; the fields of a union are allocated sequentially.
b. The compiler pads structures for word alignment; the compiler allocates exactly enough space for a union to hold all of its fields.
c. A union may contain bitfields; a structure may not.
d. The fields of a structure exist concurrently; the fields of a union do not.

59. What would be the output of the following?
Code: C

`int x=5;void print(){    printf("%d",x--);}main(){    print(x++);}`

a. 4
b. 5
c. 6
d. None of the above

60. f = fopen( fileName, "r" );

Code: C

`if( ???? ) {     fprintf( stderr, "Could not open file!" );     exit( -1 ); }`

What should replace the ???? in the code above to determine if the file could NOT be opened?

a. fclose( f )
b. f == -1
c. f != 0;
d. f == NULL

 shabbir 1Feb2007 13:24

Re: Multiple Choice Questions in C (Answers not given)

Now we have quite a few questions in C-C++.

100 Multiple choice questions in C
Top 100 C Questions Asked in Actual Interviews

 karthick.RG.Rajan 25Mar2007 23:43

Re: Multiple Choice Questions in C (Answers not given)

very useful to my interview sir

 wrecker 17Apr2007 03:33

Re: Multiple Choice Questions in C (Answers not given)

hry guys, i have solved almost all ques. m attaching file. please check if any answer is not correct...
will surely post remaining ques later...

Code:

```1.        a 2.        d 3.        c 4.        a 5.        b 6.        a 7.        d 8. 9.        a 10.        c 11.        a 12.        a 13.        b 14. 15.        a 16.        a 17.        b 18.        b 19.        c 20.        b 21.        b 22.        b 23.        d 24.        b 25. 26. 27.        d 28. 29.        c 30.        b 31.        b 32.        c 33.        d 34.        a 35.        d 36.        c 37. 38.        39.        40.        d 41.        c  (Unable to figure out) 42.        d 43.        b 44. 45.        a 46.        c 47.        b 48.        a 49. 50.        c 51.        c 57.        b 58.        d 60.        c```

 shabbir 17Apr2007 05:59

Re: Multiple Choice Questions in C (Answers not given)

Don't you think that would be a spoiler.

 sibu 17Apr2007 08:57

Re: Multiple Choice Questions in C (Answers not given)

I dont want to say whether answers are correct or not. Few questions are implementation dependant.Always you could execute and see and then try to find out reason behind the anwer. I feel that would be best way to learn

 wrecker 17Apr2007 10:17

Re: Multiple Choice Questions in C (Answers not given)

Why to be a spoiler. I thought that would just test my knowledge in C and would provide answers that are a bit confusing to those who do not know it? So to me it lot more useable than to those whom its spoiler.

 shabbir 17Apr2007 11:17

Re: Multiple Choice Questions in C (Answers not given)

Quote:
 Originally Posted by wrecker Why to be a spoiler. I thought that would just test my knowledge in C and would provide answers that are a bit confusing to those who do not know it? So to me it lot more useable than to those whom its spoiler.
I dont doubt on this.

 psapikas 2Aug2007 12:47

Re: Multiple Choice Questions in C (Answers not given)

Could you please explain to me the questions #10, #17 and #20?

#10 why does the loop ends?

#17 why does 3+big(a,b) is different than big(a,b)+3 ?

#20 The line x=new int; gives me 4 errors and 1 warning in my compiler.

Thank you

 shabbir 2Aug2007 14:12

Re: Multiple Choice Questions in C (Answers not given)

Quote:
 Originally Posted by psapikas #10 why does the loop ends?
Because the value of i becomes -1 at some point in the loop and so ++1 becomes 0 and so it breaks.

Quote:
 Originally Posted by psapikas #17 why does 3+big(a,b) is different than big(a,b)+3 ?
Because of order of precedence of the operators involved.

Quote:
 Originally Posted by psapikas #20 The line x=new int; gives me 4 errors and 1 warning in my compiler.
It should not. I have tried compiling it. What compiler you are using and what are the errors / warnings.

 All times are GMT +5.5. The time now is 21:06. Page 1 of 3123> Show 40 post(s) from this thread on one page