Question 1
EasyWhat is the output of this program?
#include <stdio.h>
int {
a[] = {, , , };
*p = a;
(, *(p + ));
;
}
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 {
a[] = {, , , };
*p = a;
(, *(p + ));
;
}
10
20
30
Garbage value
Answer: C
p points to a[0]. p + 2 points to a[2], and dereferencing it gives 30.
What is the output of this program?
#include <stdio.h>
int main(void) {
printf("%d", 7 / 2);
return 0;
}
4
3.5
Answer: D
Both operands are int, so 7 / 2 is integer division: 3.
What is the output of this program?
#include <stdio.h>
int main(void) {
printf("%d", 10 % 3);
return 0;
}
1
0
Answer: A
% gives the remainder of integer division: 10 = 3 × 3 + 1.
Which header file must be included to use printf() in C?
stdio.h
stdlib.h
math.h
string.h
Answer: A
printf and scanf are declared in <stdio.h> (standard input/output).
What is the output of this program?
#include <stdio.h>
int main(void) {
char c = 'A';
printf("%c", c + 1);
return 0;
}
66
B
Answer: B
Characters are small integers: 'A' + 1 is 66, which %c prints as 'B'.
What does the & operator return when applied to a variable, as in &x?
The address of x
A copy of x
The value of x
x AND 1
Answer: A
&x gives a pointer to x; *p reads the value at a pointer.
What is the output of this program?
#include <stdio.h>
int main(void) {
int x = 10;
int *p = &x;
printf("%d", *p);
return 0;
}
Error
20
Answer: C
p points to x, so *p reads x's value, 10.
Which function allocates memory dynamically in C?
malloc()
create()
new
alloc()
Answer: A
malloc() returns a pointer to uninitialised heap memory, which must later be released with free().
What is the output of this program?
#include <stdio.h>
int main() {
int a = 10, b = 3;
printf("%d", a / b);
return 0;
}
3
3.333333
Answer: A
Both operands are int, so / does integer division and drops the fraction.
What is the output of this program?
#include <stdio.h>
int main() {
printf("%d", 10 % 4);
return 0;
}
2
4
Answer: A
% gives the remainder: 10 = 4 × 2 + 2.
3.500000
3
3
2
A
65
10
Garbage value
3.33
4
2.5
0