C Programming MCQs

C Programming MCQs

These C Programming multiple-choice questions and their answers will help you strengthen your grip on the subject of C Programming. You can prepare for an upcoming exam or job interview with these C Programming MCQs.
So scroll down and start answering.

1: What is the only function all C programs must contain?

A.   main()

B.   program()

C.   start()

2: char* buf[100]; strcpy(buf, argv[1]); Which security risk is this code vulnerable to?

A.   Format string

B.   Stack overflow

C.   Integer overflow

D.   Race condition

E.   Heap overflow

3: Which one is NOT a reserved keyword?

A.   switch

B.   static

C.   extern

D.   intern

E.   struct

4: A C variable can start with a digit as well a letter.

A.   True

B.   False

5: Function Overloading is not supported in C.

A.   True

B.   False

6: How can you make an infinite loop in C?

A.   for(;;) { }

B.   while(1) { }

C.   loop: ... goto loop;

D.   All answers are right.

7: #ifdef __APPLE__ # include <dir/x.h> #else # include <other_dir/x.h> #endif What does it mean?

A.   It will include dir/x.h if __APPLE__ is defined, or other_dir/x.h, otherwise.

B.   It will define __APPLE__, include dir/x.h and next time will include other_dir/x.h

C.   It will define __APPLE__ and include dir/x.h

D.   It will include dir/x.h if __APPLE__ is not defined, or other_dir/x.h, otherwise.

8: What is i after the following block of code is executed : int i; i = 10/5/2/1;

A.   0

B.   1

C.   5

D.   4

9: What will be the output of: #include void main() { char a[6] = "Hello"; printf("%d", sizeof(a)); }

A.   Program will not execute.

B.   Array not initialized correctly

C.   6

D.   Compile time error

10: What is the value of the variable x? int x; x = 32 / 64;

A.   0.5

B.   0

C.   Undefined

11: What does "int *p = malloc(2);" do?

A.   It will crash your program (an int is four bytes long, not two).

B.   Nothing, it will yield a type mismatch compiler error.

C.   It will make p point to an uninitialized two-byte piece of memory allocated from the heap.

D.   It will make p point to the number 2.

12: If we pass an array as an argument of a function, what exactly get passed?

A.   a[0]th value of array

B.   a[last]th value of array

C.   All elements of an array

D.   Address of array

13: In C, a block is defined by...

A.   tabulations

B.   tags

C.   angle brackets

D.   curly braces

E.   indentation

14: int tab[3] = {0,1,2}; int i = 0; tab[++i] == ?

A.   0

B.   2

C.   1

15: In C language, && is a

A.   None of them

B.   Logical operator

C.   Arithmetic Operator

D.   Relational Operator

16: int i = 17 / 3; what is the value of i ?

A.   5

B.   6

C.   6.0

D.   5.60

E.   5.666666

17: Is C Object Oriented?

A.   No

B.   Yes

18: Which of the following special symbols are allowed in a variable name?

A.   - (hyphen)

B.   * (asterisk)

C.   _ (underscore)

D.   | (pipeline)

19: int *a, b; What is b ?

A.   An int *

B.   An int

C.   It does not compile

20: Which of the following is the correct operator to compare two integer variables?

A.   =

B.   equal

C.   ==

D.   :=

21: which of these is not valid keyword?

A.   char

B.   float

C.   var

D.   double

E.   int

22: Which of the following is not a predefined variable type?

A.   float

B.   real

C.   int

23: The end of a C statement is indicated by this character.

A.   .

B.   +

C.   :

D.   ;

24: The system function longjmp() can be used to return execution control to any user-specified point in the active function call tree.

A.   False

B.   True

25: What will be the output of this Program? #include struct Data{ char a; char *data; int value; }; main() { printf("%d\n",sizeof(struct Data)); }

A.   6

B.   3

C.   9

D.   It depends on the compiler and the hardware architecture.

E.   12

26: What is the value of p in int a,b,*p; p=&a; b=**p; printf("%d",p);

A.   value of variable b

B.   address of variable a

C.   value of variable a

D.   address of variable b

27: Will this loop terminate? int x=10; while( x-- > 0 );

A.   It will cause segfault

B.   no

C.   yes

D.   It will not compile

28: Which statement is true about double?

A.   its size depends on the implementation

B.   its size is 128 bits

C.   it's an alias of float

D.   it uses the GPU

29: How can you access the first element of an array called 'arr'?

A.   arr[0]

B.   (both of these)

C.   *arr

30: What are the different types of floating-point data in C ?

A.   float, double, long double

B.   double, long int, float

C.   short int, double, long int

D.   float, double

31: With: sizeof(char *) == 4 sizeof(char) == 1 What will sizeof(plop) for char plop[2][3] be?

A.   6

B.   14

C.   18

D.   10

32: foo[4] is equivalent of :

A.   *(&foo + 4)

B.   (*foo + 4)

C.   There is no equivalent using those notations

D.   &(foo + 4)

E.   *(foo + 4)

33: What is the output of the following code? char * str1 = "abcd"; char * str2 = "xyz"; if( str1 < str2 ) printf( "1" ); else printf( "2" );

A.   Undefined

B.   2

C.   1

34: What will the following code print? void *p = malloc(0); printf ("%d\n", p);

A.   Nothing, it will give a runtime error.

B.   Nothing, it won't compile.

C.   Unknown, it depends on what malloc will return.

D.   0

35: What is the value of 1 & 2?

A.   2

B.   0

C.   1

D.   3

36: stdarg.h defines?

A.   actual arguments

B.   formal arguments

C.   array definitions

D.   arguments with data types

E.   macros used with variable argument functions

37: What will be the output of the following? (int)b * (float)a / (double)d * (long)c

A.   double

B.   long

C.   float

D.   int

38: To send an array as a parameter to function, which one is a right way:

A.   doThis(*array)

B.   doThis(array[size])

C.   doThis(&array)

D.   doThis(array)

39: What is the output of printf("%d\n", sizeof(long) / sizeof(int))?

A.   2

B.   Depends on the implementation, but always some number > 1.

C.   1

D.   4

E.   Depends on the implementation, but always some number >= 1.

40: The main() function can be called recursively.

A.   True

B.   False

41: Which one is not a bitwise operator ?

A.   ~

B.   ^

C.   <<

D.   !

E.   |

42: What will this code print out? #include void function(char *name) { name=NULL; } main() { char *name="ELANCE"; function(name); printf("%s",name); }

A.   ELANCE

B.   NULL

C.   Sengmentation Fault

D.   It Won't Compile

43: What does malloc(0) return?

A.   NULL

B.   The program segfault

C.   The behavior is implementation-defined

D.   A unique pointer

44: The operator used to get value at address stored in a pointer "p" is :

A.   *p

B.   &p

C.   &(p)

D.   **(p)

E.   *(*p)

45: #include int main(){ int a=0; #if (a==0) printf("Equal"); #else if printf("Not equal"); #endif return 0; } Output of above program is:

A.   Garbage

B.   Null

C.   Not equal

D.   Equal

E.   Compilation error

46: For a pointer to a 3 dimensional array (*foo)[2][3][4], how many calls to malloc do you need at least to allocate its contents?

A.   24

B.   2

C.   4

D.   1

E.   3

47: What is the output of the Program : int main() { int i,j; i=1,2,3; j=(1,2,3); printf("%d %d",i,j); return 0; }

A.   0 0

B.   1 1

C.   1 3

D.   Garbage Values of i & j

E.   Compile Time Error

48: memmove() is safer than memcpy() when it comes to the location of its arguments.

A.   False

B.   True

49: What will be output if you will execute following code? #include int main(){ int x=25; if(!!x) printf("%d",!x); else printf("%d",x); return 0; }

A.   0

B.   1

C.   25

D.   -1

E.   2

50: Which function is a System Call?

A.   fopen

B.   close

C.   printf