C Programming Lab Quiz - SOLUTION
C Programming Lab Quiz - SOLUTION
#include <stdio.h
int main() {
int y = 1000;
int *x = &y;
*x = *x >> 2;
printf(“%d”, y);
return 0;
}
a) 250 b) 4000 c)500 d)1000
12. What will be the output of the following C code?
#include <stdio.h>
int main() {
int a = 2, b = 3, c;
c = ++a + b++;
printf("%d %d %d", a, b, c);
return 0;
}
a) 3 4 5 b) 3 4 6 c) 3 4 7 d)2 4 6
13. What will be the output of the following C code?
#include <stdio.h>
int main()
{
1 < 2 ? printf("1") : printf("2");
return 0;
}
a) 1 b) 2 c) 0 d) Compilation Error
14. How many times i value is checked in the following C program?
#include <stdio.h>
int main()
{ int i = 0;
while (i < 3)
i++;
printf("In while loop\n");
}
a) 2 b) 3 c) 4 d) 1
15. What is the output of the following C code:
#include <stdio.h>
void m() {
static int x = 5;
x++;
printf("%d", x); }
int main() {
m();
m();
return 0; }
a) 67 b) 55 c) 56 d) 66
16. Fill in the blanks
void calculate_area(int _______,
len int _______)
wid {
int area = _______
len * _______;
wid
printf("The area of the rectangle is: %d\n", area);
}
int main() {
int length, width;
printf("Enter the length: ");
scanf("%d", &_______);
length
calculate_area(length, width);
return 0;
}
17. Write the missing code
#include <stdio.h>
void swap_values(int *a, int *b) { int temp;
temp=*a;
*a=*b;
*b=temp;
}
int main() {
int x = 5, y = 10;
int main()
{
char str[] = "Compsci\0\Bits\0";
printf("%s\n", str);
return 0;
}