C Interview Questions and Answers for Freshers

    1 Votes

16) What is a pragma?

The #pragma preprocessor allows compiler to include or exclude compiler specific features. For example if there is a feature xxx_yyy then,
#pragma xxx_yyy(on)
Forces compiler to include the feature. Conversely, you can turn off it by the following lines:
#pragma xxx_yyy(off)


17) How to redefined macro with different value?
The #undef preprocessor can be used to reset a macro. For example,
#ifdef SAMPLE /* Checking if SAMPLE is defined */
#undef SAMPLE /* If so, then reset it */
#define SAMPLE 0 /* Then redefine with intended value */


18) What is an lvalue?

An lvalue is an expression to which a value can be assigned. The lvalue expression is the one which is located on the left side a statement, whereas an rvalue is located on the right side of a statement. Each assignment must have a valid lvalue and rvalue. The lvalue expression must refer to a storage where something can be stored. It can't be a constant.

19) How to assign one array to another?

You can't assign an array to other. Arrays are not lvalue, because they don't refer to one variable, rather a set of variables. So they can't be placed on the left hand side of an assignment statement. For example the following statement will generate compilation error.

int x[5], y[5];
x = y;

20) what is the order of operator precedence, left to right or right to left ?

None of them is standard. C does not always start evaluating left to right or right to left. Normally, function calls are done first, followed by complex expressions and then simple expressions. That is why it is best to use parenthesis in all expressions, without depending on precedence.

21) What is the difference between ++X and X++?

The ++ operator is called the incremental operator. When the operator is placed before, the variable is incremented by 1 before it is used in the statement. When the operator is placed after the variable, then the expression is evaluated first and then the variable is incremented by 1.

22) What happens when we use incremental operator in a pointer?

It depends upon the type of the pointer. It gets incremented by the size of the data type, the pointer is pointing to. For example

char p; p++; /* here p increments by 1*/
int p; p++;/* here p increments by 4(for 32 bit system)*/

23) What will be output of the following code snippet?

int num1=5;
int num2=5;
num1 =num1++ + num1--;
num2 =++num2 + --num2;
printf("num1=%d num2=%d",num1,num2);

Output will be num1=10 num2=10.

24) Can the sizeof operator be used to tell the size of an array passed to a function?

No. The sizeof() operator can't tell the size of an array, because it is actually a pointer to the data type of the array.

25) Can you change the value of an array tag?

No. An array tag can't be used as a storage, because it is not an Lvalue. It can be thought as a pointer to the datatype of the array which is constant and which can't be changed or assigned dynamically.

Page 3 of 8

Popular Videos


How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

C++ Interview Questions and Answers for Freshers, Experienced
Advanced C Interview Questions and Answers for Experienced
Embedded C Interview Questions and Answers