Wa0028.
Wa0028.
Sai University
Introduction to Programming
Test-2
#include<stdio.h>
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
(a) 5
(b) 6
(c) Compilation Error
(d) Runtime Error
1
(c) Array size can be changed dynamically in C
(d) Arrays in C are always passed by value to functions
5. What would be the output of the following code?
#include<stdio.h>
int main() {
char ch = ’A’;
printf("%d", ch);
return 0;
}
(a) 65
(b) A
(c) Compilation Error
(d) Random value
#include<stdio.h>
int main() {
int a = 10;
if(a = 0)
printf("Zero");
else
printf("Non-zero");
return 0;
}
(a) Zero
(b) Non-zero
(c) Compilation Error
(d) Runtime Error
2
(c) Both (a) and (b)
(d) None of the above
9. What would be the output of the following code?
#include<stdio.h>
int main() {
int a = 2, b = 5, c = 10;
printf("%d", a * b / c);
return 0;
}
(a) 1
(b) 0
(c) 2.5
(d) Compilation Error
10. Which of the following will cause a logical error but not a compilation
error?
(a) Using = instead of ==
(b) Forgetting to declare a variable
(c) Missing return statement in int main()
(d) Incorrect printf format specifier
11. What is wrong with the following code?
#include<stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[5]);
return 0;
}
(a) Nothing
(b) Array index out of bounds
(c) Syntax error
(d) Compilation Error
3
(d) None of the above
13. What would be the output of the following code?
#include<stdio.h>
int main() {
int a = 5, b = 10;
printf("%d", a < b ? a : b);
return 0;
}
(a) 5
(b) 10
(c) Compilation Error
(d) None of the above
#include<stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf("%d", arr[3]);
return 0;
}
(a) 4
(b) 3
(c) 5
(d) Compilation Error