C MCQ set number 00687

1. enum types are processed by
a) Compiler
b) Preprocessor
c) Linker
d) Assembler

Answer

Answer: a [Reason:] None.

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("aidlorclassn");
  5.         return 0;
  6.     }

a) aidloclass
b) aidlo
class
c) classundry
d) aidlo

Answer

Answer: c [Reason:] r is carriage return and moves the cursor back. sanfo is replaced by class
Output:
$ cc pgm8.c
$ a.out
classundry

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("aidlornclassn");
  5.         return 0;
  6.     }

a) aidloclass
b) aidlo
class
c) classundry
d) aidlo

Answer

Answer: b [Reason:] rn combination makes cursor move to nextline.
Output:
$ cc pgm9.c
$ a.out
aidlo
class

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         const int p;
  5.         p = 4;
  6.         printf("p is %d", p);
  7.         return 0;
  8.     }

a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value

Answer

Answer: b [Reason:] Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
Output:
$ cc pgm10.c
pgm10.c: In function ‘main’:
pgm10.c:5: error: assignment of read-only variable ‘p’

5. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 4;
  5.         int *const p = &k;
  6.         int r = 3;
  7.         p = &r;
  8.         printf("%d", p);
  9.     }

a) Address of k
b) Address of r
c) Compile time error
d) Adress of k + address of r

Answer

Answer: c [Reason:] Since the pointer p is declared to be constant, trying to assign it with a new value results in an error.
Output:
$ cc pgm11.c
pgm11.c: In function ‘main’:
pgm11.c:7: error: assignment of read-only variable ‘p’
pgm11.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int * const’

6. Which is false?
a) Constant variables need not be defined as they are declared and can be defined later
b) Global constant variables are initialised to zero
c) const keyword is used to define constant values
d) You cannot reassign a value to a constant variable

Answer

Answer: a [Reason:] Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
Hence the statement a is false.

7. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int const k = 5;
  5.         k++;
  6.         printf("k is %d", k);
  7.     }

a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed

Answer

Answer: d [Reason:] Constant variable has to be declared and defined at the same time. Trying to change it results in an error.
Output:
$ cc pgm12.c
pgm12.c: In function ‘main’:
pgm12.c:5: error: increment of read-only variable ‘k’

8. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     int const print()
  3.     {
  4.         printf("aidlo.com");
  5.         return 0;
  6.     }
  7.     void main()
  8.     {
  9.         print();
  10.     }

a) Error because function name cannot be preceded by const
b) aidlo.com
c) aidlo.com is printed infinite times
d) Blank screen, no output

Answer

Answer: b [Reason:] None.
Output:
$ cc pgm13.c
$ a.out
aidlo.com

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.