Question 31
MediumWhat is the output of this program?
#include <stdio.h>
int main(void) {
char s[] = "hello";
printf("%zu", sizeof(s));
return 0;
}
- A.
5
- B.
8
- C.
6
- D.
4
Sign up free to see the answer and a step-by-step explanation.
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 main(void) {
char s[] = "hello";
printf("%zu", sizeof(s));
return 0;
}
5
8
6
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(void) {
int a[] = {10, 20, 30, 40};
int *p = a;
printf("%d", *(p + 2));
return 0;
}
Error
20
30
10
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(void) {
int a = 0, b = 0;
int r = a && (b = 1);
r = a || (b = 1);
printf("%d %d", a, b);
return 0;
}
1 1
0 1
0 0
1 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[] = {10, 20, 30, 40};
int *p = a + 1;
printf("%d %d %d", *p, *(p + 2), p[-1]);
return 0;
}
20 40 10
20 30 10
10 30 20
21 22 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() {
int x = 5;
int *p = &x;
int **q = &p;
**q = 12;
printf("%d", x);
return 0;
}
12
5
Address of x
Compilation error
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[] = "hello";
printf("%zu %zu", sizeof(s), sizeof("hi"));
return 0;
}
6 2
5 2
8 8
6 3
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 i, s = 0;
for (i = 0; i < 10; i++) {
if (i % 3 == 0) continue;
if (i == 8) break;
s += i;
}
printf("%d %d", s, i);
return 0;
}
21 8
27 10
19 8
19 10
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 = 7;
switch (x % 4) {
case 1: printf("one ");
case 3: printf("three ");
case 2: printf("two ");
break;
default: printf("other ");
}
return 0;
}
three two
other
three
one three two
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() {
unsigned int u = 0;
u = u - 1;
printf("%d", u > 100);
return 0;
}
Compilation error
-1
1
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 = 10, b = 3;
printf("%d %d %d %.2f", a / b, a % b, -a / b, (float)a / b);
return 0;
}
3 1 -3 3.00
3 1 -3 3.33
3 1 -4 3.33
3.33 1 -3 3.33
Sign up free to see the answer and a step-by-step explanation.