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?
-
#include <stdio.h>
-
int main()
-
{
-
printf("aidlorclassn");
-
return 0;
-
}
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?
-
#include <stdio.h>
-
int main()
-
{
-
printf("aidlornclassn");
-
return 0;
-
}
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?
-
#include <stdio.h>
-
int main()
-
{
-
const int p;
-
p = 4;
-
printf("p is %d", p);
-
return 0;
-
}
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?
-
#include <stdio.h>
-
void main()
-
{
-
int k = 4;
-
int *const p = &k;
-
int r = 3;
-
p = &r;
-
printf("%d", p);
-
}
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?
-
#include <stdio.h>
-
void main()
-
{
-
int const k = 5;
-
k++;
-
printf("k is %d", k);
-
}
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?
-
#include <stdio.h>
-
int const print()
-
{
-
printf("aidlo.com");
-
return 0;
-
}
-
void main()
-
{
-
print();
-
}
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