250+ TOP MCQs on Automatic Variables and Answers

C quiz on “Automatic Variable”. One shall practice these quizzes to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C quiz comes with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C quiz on “Automatic Variable” along with answers, explanations and/or solutions:

1. What is the scope of an automatic variable?
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Within the block it appears & Within the blocks of the block it appears
Answer: d
Clarification: None.

2. Automatic variables are allocated space in the form of a __________
a) stack
b) queue
c) priority queue
d) random
Answer: a
Clarification: None.

3. Which of the following is a storage specifier?
a) enum
b) union
c) auto
d) volatile
Answer: c
Clarification: None.

4. If storage class is not specified for a local variable, then the default class will be auto.
a) True
b) False
c) Depends on the standard
d) None of the mentioned
Answer: a
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     void foo(auto int i);
  3.     int main()
  4.     {
  5.         foo(10);
  6.     }
  7.     void foo(auto int i)
  8.     {
  9.         printf("%dn", i );
  10.     }

a) 10
b) Compile time error
c) Depends on the standard
d) None of the mentioned
Answer: b
Clarification: None.

6. Automatic variables are stored in ________
a) stack
b) data segment
c) register
d) heap
Answer: a
Clarification: None.

7. What linkage does automatic variables have?
a) Internal linkage
b) External linkage
c) No linkage
d) None of the mentioned
Answer: c
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         auto i = 10;
  5.         const auto int *p = &i;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Depends on the standard
d) Depends on the compiler
Answer: a
Clarification: None.

contest

250+ TOP MCQs on Address Arithmetic and Answers

C questions and puzzles on “Address Arithmetic”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C questions and puzzles on “Address Arithmetic” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         double *ptr = (double *)100;
  5.         ptr = ptr + 2;
  6.         printf("%u", ptr);
  7.     }

a) 102
b) 104
c) 108
d) 116
Answer: d
Clarification:None

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int *p = (int *)2;
  5.         int *q = (int *)3;
  6.         printf("%d", p + q);
  7.     }

a) 2
b) 3
c) 5
d) Compile time error
Answer: d
Clarification: None.

3. Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a – b
c) a * b
d) a / b
Answer: b
Clarification: None.

4. What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
Answer: c
Clarification: None.

5. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ b
c) a & b
d) None of the mentioned
Answer: d
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%ct%c", *(p + 1), s[1]);
  7.     }

a) h e
b) e l
c) h h
d) e e
Answer: d
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%ct%c", *p, s[1]);
  7.     }

a) e h
b) Compile time error
c) h h
d) h e
Answer: d
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *n = "cjn";
  6.         char *p = s + n;
  7.         printf("%ct%c", *p, s[1]);
  8.     }

a) h e
b) Compile time error
c) c o
d) h n
Answer: b
Clarification: None.

250+ TOP MCQs on Complicated Declarations and Answers

C question bank on “Complicated Declarations”. One shall practice these questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C question bank comes with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C question bank on “Complicated Declarations” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         no = 8;
  11.         printf("%d", no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: b
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Run time error
b) Nothing
c) hello
d) Varies
Answer: c
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     struct student
  3.     {
  4.         int no = 5;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Nothing
b) Compile time error
c) hello
d) Varies
Answer: b
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         student s;
  10.         s.name = "hello";
  11.         printf("hello");
  12.     }

a) Nothing
b) hello
c) Compile time error
d) Varies
Answer: c
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("%s", s.name);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: c
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     struct student s;
  8.     void main()
  9.     {
  10.         s.no = 8;
  11.         printf("%s", s.name);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: a
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int *((*x)())[2];
  5.         x();
  6.         printf("after xn");
  7.     }
  8.     int *((*x)())[2]
  9.     {
  10.         int **str;
  11.         str = (int*)malloc(sizeof(int)* 2);
  12.         return str;
  13.     }

a) Compile time error
b) Undefined behaviour
c) After x
d) None of the mentioned
Answer: a
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     void (*(f)())(int, float);
  3.     void (*(*x)())(int, float) = f;
  4.     void ((*y)(int, float));
  5.     void foo(int i, float f);
  6.     int main()
  7.     {
  8.         y = x();
  9.         y(1, 2);
  10.     }
  11.     void (*(f)())(int, float)
  12.     {
  13.         return foo;
  14.     }
  15.     void foo(int i, float f)
  16.     {
  17.         printf("%d %fn", i, f);
  18.     }

a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash
Answer: a
Clarification: None.

9. What does this declaration say?

a) y is pointer to the function which returns pointer to integer array
b) y is pointer to the function which returns array of pointers
c) y is function which returns function pointer which in turn returns pointer to integer array
d) y is function which returns array of integers
Answer: a
Clarification: None.

10. What will be the output of the following C code?

  1.     #include 
  2.     void (*(f)())(int, float);
  3.     typedef void (*(*x)())(int, float);
  4.     void foo(int i, float f);
  5.     int main()
  6.     {
  7.         x = f;
  8.         x();
  9.     }
  10.     void (*(f)())(int, float)
  11.     {
  12.         return foo;
  13.     }
  14.     void foo(int i, float f)
  15.     {
  16.         printf("%d %fn", i, f);
  17.     }

a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
Answer: a
Clarification: None.

11. What will be the output of the following C code?

  1.     #include 
  2.     void (*(f)())(int, float);
  3.     typedef void (*(*x)())(int, float);
  4.     void foo(int i, float f);
  5.     int main()
  6.     {
  7.         x p = f;
  8.         p();
  9.     }
  10.     void (*(f)())(int, float)
  11.     {
  12.         return foo;
  13.     }
  14.     void foo(int i, float f)
  15.     {
  16.         printf("%d %fn", i, f);
  17.     }

a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
Answer: d
Clarification: None.

250+ TOP MCQs on Unions and Answers

C Objective Questions on “Unions”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Unions” along with answers, explanations and/or solutions:

1. The size of a union is determined by the size of the __________
a) First member in the union
b) Last member in the union
c) Biggest member in the union
d) Sum of the sizes of all members
Answer: c
Clarification: None.

2. Which member of the union will be active after REF LINE in the following C code?

  1.     #include 
  2.     union temp
  3.     {
  4.         int a;
  5.         float b;
  6.         char c;
  7.     };
  8.     union temp s = {1,2.5,’A’}; //REF LINE

a) a
b) b
c) c
d) Such declaration are illegal
Answer: a
Clarification: None.

3. What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1)

  1.     #include 
  2.     union uTemp
  3.     {
  4.         double a;
  5.         int b[10];
  6.         char c;
  7.     }u;

a) 4
b) 8
c) 40
d) 80
Answer: c
Clarification: None.

4. What type of data is holded by variable u int in the following C code?

  1.     #include 
  2.     union u_tag
  3.     {
  4.         int ival;
  5.         float fval;
  6.         char *sval;
  7.     } u;

a) Will be large enough to hold the largest of the three types;
b) Will be large enough to hold the smallest of the three types;
c) Will be large enough to hold the all of the three types;
d) None of the mentioned
Answer: a
Clarification: None.

5. Members of a union are accessed as________________
a) union-name.member
b) union-pointer->member
c) both union-name.member & union-pointer->member
d) none of the mentioned
Answer: c
Clarification: None.

6. In the following C code, we can access the 1st character of the string sval by using _______

  1.     #include 
  2.     struct
  3.     {
  4.         char *name;
  5.         union
  6.         {
  7.             char *sval;
  8.         } u;
  9.     } symtab[10];

a) *symtab[i].u.sval
b) symtab[i].u.sval[0].
c) You cannot have union inside structure
d) Both *symtab[i].u.sval & symtab[i].u.sval[0].
Answer: d
Clarification: None.

7. What will be the output of the following C code (Assuming size of int and float is 4)?

  1.     #include 
  2.     union
  3.     {
  4.         int ival;
  5.         float fval;
  6.     } u;
  7.     void main()
  8.     {
  9.         printf("%d", sizeof(u));
  10.     }

a) 16
b) 8
c) 4
d) 32
Answer: c
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     union stu
  3.     {
  4.         int ival;
  5.         float fval;
  6.     };
  7.     void main()
  8.     {
  9.         union stu r;
  10.         r.ival = 5;
  11.         printf("%d", r.ival);
  12.     }

a) 9
b) Compile time error
c) 16
d) 5
Answer: d
Clarification: None.

250+ TOP MCQs on Line Input & Output and Answers

tough C questions on “Line Input & Output”. One shall practice these questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C programming questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of tough C questions on “Line Input & Output” along with answers, explanations and/or solutions:

1. What is the size of array “line” used in fgets(line, maxline, *fp) function?
a) maxline – 1
b) maxline
c) maxline + 1
d) Size is dynamic
Answer: b
Clarification: None.

2. What will be the output of the following C function when EOF returns?

   int fputs(char *line, FILE *fp)

a) ‘�’ character of array line is encountered
b) ‘n’ character in array line is encountered
c) ‘t’ character in array line is encountered
d) When an error occurs
Answer: d
Clarification: None.

3. Identify X library function for line input and output in the following C code?

  1.     #include 
  2.     int X(char *s, FILE *iop)
  3.     {
  4.         int c;
  5.         while (c = *s++)
  6.         putc(c, iop);
  7.         return ferror(iop) ? EOF : 0;
  8.     }

a) getc
b) putc
c) fgets
d) fputs
Answer: d
Clarification: None.

4. Which function has a return type as char pointer?
a) getline
b) fputs
c) fgets
d) all of the mentioned
Answer: c
Clarification: None.

5. Which of the following is the right declaration for fgets() inside the library?
a) int *fgets(char *line, int maxline, FILE *fp);
b) char *fgets(char *line, int maxline, FILE *fp);
c) char *fgets(char *line, FILE *fp);
d) int *fgets(char *line, FILE *fp);
Answer: b
Clarification: None.

6. what is the return value of fputs()?
a) EOF if an error occurs
b) Non-negative if no error
c) EOF if an error occurs & Non-negative if no error
d) None of the mentioned
Answer: c
Clarification: None.

7. gets() and puts() operate on ___________
a) stdin and stdout
b) files
c) stderr
d) nothing
Answer: a
Clarification: None.

8. gets() does the following when it reads from stdin.
a) Deletes the ‘t’
b) Puts adds it.
c) Deletes the terminating ‘n’
d) Nothing
Answer: c
Clarification: None.

contest

250+ TOP MCQs on scanf and Answers

C Multiple Choice Questions & Answers on “scanf – 2”.

1. Select the correct value of i from given options i=scanf(“%d %d”, &a, &b);
a) 1
b) 2
c) 3
d) No value assigned
Answer: b
Clarification: i stores the number of read data from the stream. It is useful for detecting an error in data input.

2. If the user enters 1 3.2 s, what value will be returned by the scanf()?

scanf("%d %f %c", &s1, &s2, &s3);

a) 1
b) 2
c) 3
d) No return value
Answer: c
Clarification: When the scanf() function completes reading all the data values, it returns number of values that are successfully read.

3. If the user enters 1 s 3.2, what value will be returned by the scanf()?

scanf("%d %f %c", &a, &b, &c);

a) 1
b) 2
c) 3
d) no return value
Answer: a
Clarification: scanf() returns the number of values that are successfully read. In the above statement, only integer value is read successfully.

4. What error will be generated on using incorrect specifier for the datatype being read?
a) compile error
b) run-time error
c) logical error
d) no error
Answer: b
Clarification: Using an incorrect specifier for the datatype being read will generate a run-time error.

5. What is the prototype of scanf function?
a) scanf(“controlstring”,arg1,arg2,arg3,….,argn);
b) scanf(“control string”, variable list);
c) scanf(” varible list,”, control string);
d) scanf(“arg1,arg2,arg3,….,argn”, control string);
Answer: a
Clarification: The syntax of the scanf() can be given as,scanf(“control string”, arg1,arg2,arg3,….,argn);

6. Control string specifies the type and format of the data that has to be obtained from the keyboard.
a) true
b) false
Answer: a
Clarification: The control string specifies the type and format of the data that has to be obtained from the keyboard and store in the memory locations pointed by the arguments arg1,arg2….argn.

7. What is the qualifying input for the type specifier G?
a) floating point numbers
b) floating point numbers in exponential format
c) floating point numbers in the shorter of exponential format
d) not a type specifier
Answer: c
Clarification: G is a type specifier used to take an input of floating point numbers in the shorter of exponential format.

8. scanf() is a predefined function in______header file.
a) stdlib. h
b) ctype. h
c) stdio. h
d) stdarg. h
Answer: c
Clarification: scanf() is a predefined function in “stdio.h” header file.printf and scanf() carry out input and output functions in C. These functions statements are present in the header file stdio.h.

9. What does the C statement given below says?

a) read string with minimum 7 characters.
b) read string with maximum 7 characters
c) read string exactly to 7 characters
d) read string with any number of characters
Answer: b
Clarification: In the above statement the control string specifies the size of string to be 7(i.e only 7 characters can be entered in a string).

10. What is the meaning of the following C statement?

a) read all character except new line
b) read all characters
c) read only new line character
d) syntax error
Answer: a
Clarification: The symbol ^ when used before a escape sequence, does not read from the console.