0% found this document useful (0 votes)
67 views

C Programming Lab Quiz - SOLUTION

Uploaded by

Harshit Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

C Programming Lab Quiz - SOLUTION

Uploaded by

Harshit Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

QUIZ 1 [SESSION: 2023-24]

Name of the Student:_________________________ Admission Number:________________

Subject: C Programming Lab (CSI102)


Time: 20 Minutes
Semester: Winter Total Marks: 20 Marks
Note: Answer ALL questions, each carry One Mark, there may be multiple Answers, No Marks for partail Answers
1. What will be the output of the following program?
#include <stdio.h>
int main(){ a) 6.0/5.0 is 1.2 b) 6.0/5.0 is 1.200000
float a=5.0, b=6.0, c; c) 6.0/5.0 is 1.0 d) 6.0/5.0 is 1.000000
c=b/a;
printf("%0.1f/%0.1f is %f", b, a, c);
return 0; }
2. What will be the output of the following program?
#include<stdio.h>
int main(){
int a=8, b=3, x, y;
a) x=11, y=1 b) x=11, y=0
x=(a>b)?(a+b):(a-b);
c) x=1, y=0 d) x=11, y=11
y=(a<b)?(a&b):(a|b);
printf("x=%d, y=%d",x, y);
return 0; }
3. What will be the output of the following program?
#include <stdio.h>
int main() {
int n = 10, count = 0, sum = 0; a) 10 44 b) 11 44
while(n++>0){ c) 10 45 d) None of these
n -= 2; count++;
sum +=n;
}
printf("%d %d",count,sum);
return 0;}
4. What will be the output of the following program?
#include<stdio.h>
int main(){
int i,*ptr,arr[5]={1,2,3,4,5};
ptr=arr; a) Compile time error b) 11 21 31 41 51
for(i=0;i<5;i++) c) 12 23 34 45 50 d) 11 22 33 44 55
printf("%d%d ",ptr[i],*(arr+i));
return 0; }
5. What will be the output of the following program?
#include<stdio.h>
int func(int m, int n){
if(n<0) return -n; a) 85 b) 84
else return m+func(m*n,n-2); c) 83 d) None of these
}
int main(){
printf("%d ",func(4,5));
return 0;
}
6. In the program below, what would you put in place of “?” to print “Quiz”?
#include <stdio.h> Answer:___________________
(arr+2)
int main(){
char arr[] = "MYQuiz";
printf("%s", ?);
return 0;
}
7. The value printed by the following program is(Answer:___________________)
30
void f(int* p, int m)
{
m = m + 5;
*p = *p + m;
}
int main() {
int i=5, j=10;
f(&i, j);
printf("%d", i+j); return 0; }
a.) 10 b.) 20 c.) 30 d.) 40
8. Which of the following code snippets are valid?
a.) #include <studio.h> b.) scanf(“%d”,a);
c.) if(a==b&&a==c) d.) printf(“the result is%d”,a);

9. What will be the output of the following program?


#include <stdio.h>
int main () {
char A[10] = "53FB61R22";
int i, sum = 0;
for (i=0; A[i]; ++i) {
if (A[i] < '0') continue;
if (A[i] > '9') continue;
sum += A[i] -'0';
}
printf("sum = %d", sum);
return 0;
}
a) 17 b) 19 c) Infinite loop d) 305
10. What will the output of the following program be?
#include <stdio.h>
int main () {
if (-5) printf("W");
if (5/6) printf("X");
else printf("Y");
printf("Z");
return 0;
}
a) XYZ b) WYZ c) WXZ d) XYZ
11. What will the output of the following C code?

#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

printf("Enter the width: ");


scanf("%d", &_______);
width

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;

printf("Original values: x = %d, y = %d\n", x, y);


swap_values(&x, &y); // Pass addresses of x and y
printf("Swapped values: x = %d, y = %d\n", x, y);
return 0;
}
18. What would be the output of the following code?
int i = 5;
do {
printf("%d ", i);
i--;
} while (i >= 0);
a) 5 4 3 2 1 b) 4 3 2 1 0 c) 5 d) None of the above

19. What will be the output of the following code?


#include<stdio.h>
#include<string.h>

int main()
{
char str[] = "Compsci\0\Bits\0";
printf("%s\n", str);
return 0;
}

a) Bits b) Compsci c) Compsci Bits d) Compsci\0Bits

20. What will be the output of the following code?


include<stdio.h>
int main() {
int a = 5, b = 2;
float c;
c = a / b;
printf("%f", c);
return 0;
}
a) 2.500000 b) 2.000000 c) 2.600000 d) Compilation Error

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy