|
C and C++ Interview Questions |
4. Which bit wise operator is suitable for putting On a particular bit in a number?
Ans:
The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON:
some_int = some_int | KBit24;
|
Ex - 1: What is the Output?
void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}
Ans:
0 65535 |
Ex - 2: What is the output?
void main()
{
int i=i++,j=j++,k=k++;
printf(“%d%d%d”,i,j,k);
}
Ans:
Garbage values.
Explanation:
An identifier is available to use in program code from the point of its declaration. So expressions such as i = i++ are valid statements. The i, j and k are automatic variables and so they contain some garbage value. Garbage in is garbage out (GIGO). |
Ex - 3: What is the Output?
void main()
{
static int i=i++, j=j++, k=k++;
printf(“i = %d j = %d k = %d”, i, j, k);
}
Ans:
i = 1 j = 1 k = 1
Explanation:
Since static variables are initialized to zero by default. |
|
|