Question 41
MediumWhat is the output of this program?
#include <stdio.h>
int {
n = ;
x = ;
(x) {
n += x & ;
x >>= ;
}
(, n);
;
}
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this program?
#include <stdio.h>
int {
n = ;
x = ;
(x) {
n += x & ;
x >>= ;
}
(, n);
;
}
1
13
3
4
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <stdio.h>
int main() {
struct P { int x; int y; } a = {1, 2}, b;
b = a;
b.x = 9;
printf("%d %d", a.x, b.x);
return 0;
}
Compilation error
9 9
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <stdio.h>
int main() {
char s[] = "abcde";
char *p = s;
while (*p) p++;
printf("%d", (int)(p - s));
return 0;
}
5
0
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <stdio.h>
int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int s = 0;
for (int i = 0; i < 3; i++)
s += a[i][2 - i];
printf("%d", s);
return 0;
}
15
12
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <stdio.h>
int main() {
int x = 10;
int y = (x > 5) ? (x < 20 ? 1 : 2) : 3;
printf("%d", y);
return 0;
}
10
1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <stdio.h>
int main() {
static int calls;
for (int i = 0; i < 3; i++)
calls++;
printf("%d", calls);
return 0;
}
1
0
Sign up free to see the answer and a step-by-step explanation.
What is the difference between malloc() and calloc() in C?
calloc() allocates on the stack
calloc() initialises the memory to zero and takes a count and size; malloc() leaves it uninitialised
malloc() is faster always and zeroes memory
They are identical
Sign up free to see the answer and a step-by-step explanation.
What is a dangling pointer?
A pointer that still holds the address of memory that has been freed or gone out of scope
A pointer to a function
A NULL pointer
An uninitialised integer
Sign up free to see the answer and a step-by-step explanation.
What does the declaration int (*fp)(int, int); declare?
A function returning a pointer to int
A pointer to a function taking two ints and returning an int
A pointer to an int array
An array of two ints
Sign up free to see the answer and a step-by-step explanation.
Why should the result of realloc() be stored in a temporary pointer first?
If it fails it returns NULL, and assigning that directly would lose the original block
realloc() always moves the block
It never fails
realloc() frees memory twice
Sign up free to see the answer and a step-by-step explanation.
1 1
1 9
4
6
45
18
2
3
3
Garbage value