c preprocessor questions

C preprocessor directive Test

1. Which of the following are C preprocessors?

a) #ifdef
b) #define
c) #endif
d) all of the mentioned

Show Answer

Answer: c
Explanation: It is primarily used for running a function upon exiting the program.

2.C preprocessor ?

a. Take care of conditional compilationg
b. Take care of include files
c. act before compilation
d. All of above

Show Answer

Answer: Option d
Explanation:no

3. A preprocessor command ?

a. need not start on a new line
b. need not start on the first column
c. comes before the first executable statement
d. has # as the first character

Show Answer

Answer: Option d

4. What is the output of the following program ?

#include< stdio.h >
int
main()
{
char ptr;
char arr[10]={1,2,3,4,5,6,9,8};
ptr=(arr+1)[5];
printf(“%d”, ptr);
return 0;

a. 4
b. 6
c. 5
d. Error

Show Answer

The correct option is (b)
Explanation:
a[i] is equals to *(a + i), so (arr+ 1)[5] is *(arr + 1 + 5), i.e. arr[6].

5. An Array elements always stored in ___________ memory location ?

a. Sequential
b. Sequential and random
c. Random
d. Non of these

Show Answer

The correct option is (a)
Explanation:

6. What will be print after execution of the program?

#include< stdio.h >
int
main()
{
int num[10]={4,5,6,7,8};
printf( “%d”,num[5]);
return 0;
}

a. Garbage value
b. 0
c. 6
d. 8

Show Answer

The correct option is (b)
Explanation:
When an array is initialized at the time of declaration then the remaining elements of the array is initialized to 0 by the compiler default.