0% found this document useful (0 votes)
87 views41 pages

C Exercise Practice Questions

The document contains 15 multiple choice questions about C programming concepts like data types, operators, functions, input/output, etc. Each question is followed by the corresponding answer. Some key concepts covered include variable declaration, precedence of operators, return values of functions like printf(), type casting, and syntax errors.

Uploaded by

agrim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views41 pages

C Exercise Practice Questions

The document contains 15 multiple choice questions about C programming concepts like data types, operators, functions, input/output, etc. Each question is followed by the corresponding answer. Some key concepts covered include variable declaration, precedence of operators, return values of functions like printf(), type casting, and syntax errors.

Uploaded by

agrim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

C Programming

Exercise
Q1. Identify the error
#include < stio.h>
int main()
{
a=2;
printf (“ The value is %d”, a);
return 0;
}
Exercise
Q1. Identify the error
#include < stio.h>
int main()
{
a=2;
printf (“ The value is %d”, a);
return 0;
}

Ans1. Compilation error


There is no such syntax for file or directory.
Exercise
Q2. What is the output of this program?
#include <stdio.h>
int main()
{
printf (“ Variable! %d”, x);
return 0;
}
Exercise
Q2. What is the output of this program?
#include <stdio.h>
int main()
{
printf (“ Variable! %d”, x);
return 0;
}
Ans2. Compile time error
Since x is not declared.
Exercise
Q3. What is the output of this program?
#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
Exercise
Q3. What is the output of this program?
#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
Ans3. 3
A C program can have same function name and same variable name.
Exercise
Q4. What is the output of this program?
#include <stdio.h>
int main()
{
int i;
i = printf ("letsfindcourse");
i = printf("%d ", i);
return 0;
}
Exercise
Q4. What is the output of this program?
#include <stdio.h>
int main()
{
int i;
i = printf("letsfindcourse");
i = printf("%d ", i);
return 0;
}
Ans4. letsfindcourse 14
In C, printf() returns the number of characters successfully written on the output. Here letsfindcourse contain 14 character
therefore i = 14
Exercise
Q5. What is the output of this program?
printf ( "%d" , printf ( "hello" ) );
Exercise
Q5. What is the output of this program?
printf ( "%d" , printf ( "hello" ) );
Ans5. hello5
Firstly inner printf executes and will print hello now this return the number of character printed that is 5 and
this will be printed by outer printf . Hence output is hello5
Exercise
Q6. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 3;
printf("%d");
return 0;
}
Exercise
Q6. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 3;
printf("%d");
return 0;
}
Ans6. Garbage value
As there is no declaration of variable a in printf function, a standard C compiler printf some garbage value as an
output.
Exercise
Q7. What is the output of this program?
#include <stdio.h>
int main()
{
float a = 3;
a = 91.827345;
printf("%.2f ”, a);
return 0;
}
Exercise
Q7. What is the output of this program?
#include <stdio.h>
int main()
{
float a = 3;
a = 91.827345;
printf("%.2f ”, a);
return 0;
}
Ans7. 91.83
Exercise
Q8. What is the output of this program?
#include <stdio.h>
int main()
{
10 + 2*10 + 10/2*10
int a = 10, b=2, x=0; 10 + 20 + 10/2*10
x= a+b*a+10/2*a; 10+20+5*10
10+20+50
printf(“value is = %d ”, x); 80
return 0;
}
Exercise
Q8. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 10, b=2, x=0;
x= a+b*a+10/2*a;
printf(“value is = %d ”, x);
return 0;
}
Ans 7. Value is = 80
Exercise
Q9. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 1, b=2, c=0, d=4,e;
e= c+d = b*a;
printf(“%d ”, “%d\n”, e, d);
return 0;
}
Exercise
Q9. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 1, b=2, c=0, d=4,e;
e= c+d = b*a;
printf(“%d ”, “%d\n”, e, d);
return 0;
}
Ans9. Syntax error
Exercise
Q10. What is the output of a?
#include <stdio.h>
int main()
{
int a;
a= 10+ 4.867;
printf(“%d ”, a);
return 0;
}
Exercise
Q10. What is the output of a?
#include <stdio.h>
int main()
{
int a;
a= 10+ 4.867;
printf(“%d ”, a);
return 0;
}
Ans10. 14
Exercise
Q11. What is the output of a?
#include <stdio.h>
int main()
{
float var;
var= 3.5+ 4.5;
printf(“%f ”, var);
return 0;
}
Exercise
Q11. What is the output of a?
#include <stdio.h>
int main()
{
float var;
var= 3.5+ 4.5;
printf(“%f ”, var);
return 0;
}
Ans11. 8.000000
Exercise
Q12. What is the output of a?
#include <stdio.h>
int main()
{
int var;
var= 3.5;
printf(“%f ”, var);
return 0;
}
Exercise
Q12. What is the output of a?
#include <stdio.h>
int main()
{
int var;
var= 3.5;
printf(“%f ”, var);
return 0;
}
Ans12. 0.000000
Exercise
Q13. What is the value of x in this code?
#include <stdio.h>
int main()
{
int x;
x= 4*5/2+9;
printf(“%d ”, x);
return 0;
}
Exercise
Q13. What is the value of x in this code?
#include <stdio.h>
int main()
{
int x;
x= 4*5/2+9;
printf(“%d ”, x);
return 0;
}
Ans13. 19
Exercise
Q14. What is the output of this code?
#include <stdio.h>
int main()
{
int x, y;
y= 3;
x= 7%4*3/2;
printf(“The value of x is %d ”, x);
return 0;
}
Exercise
Q14. What is the output of this code?
#include <stdio.h>
int main()
{
int x, y;
y= 3;
x= 7%4*3/2;
printf(“The value of x is %d ”, x);
return 0;
}
Ans14. The value of x is 4.
Exercise
Q14. What is the output of this code?
#include <stdio.h>
int main()
{
int a, c ; float b;
a= 20;
b= 15.6;
printf(“%d ”, c);
return 0;
}
Exercise
Q14. What is the output of this code?
#include <stdio.h>
int main()
{
int a, c ; float b;
a= 20;
b= 15.6;
printf(“%d ”, c);
return 0;
}
Ans14. garbage value
Exercise
Q15. What will be the output of this code?
#include <stdio.h>
int main()
{
int a=5;
a= 1, 2, 3;
printf(“%d ”, a);
return 0;
}
Exercise
Q15. What will be the output of this code?
#include <stdio.h>
int main()
{
int i=5;
i= 1, 2, 3;
printf(“%d ”, i);
return 0;
}
Ans15. 1
Comma acts as an operator. The assignment operator has higher precedence than comma operator. So, the
expression is considered as (i = 1), 2, 3 and 1 gets assigned to variable i
Home Assignment
Q1. Identify the error
include < stdio.h>
int main()
{
int a=2;
printf (“ The value is %d”, a);
return 0;
}
Q2. What is the output of this program?
#include <stdio.h>
int main()
{
printf (“ Variable! %d”, a);
return 0;
}
Q3. What is the output of this program?
#include <stdio.h>
int main()
{
float a = 3;
a = 91.827345;
printf("%.3f ”, a);
return 0;
}
Q4. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 5 * 3 + 2 – 4;
printf(“%d”, a);
return 0;
}

35
Q5. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 2 + 4 + 3 * 5 / 3 - 5;
printf("%d", a);
return 0;

}
Q6. What is the output of this program?
#include <stdio.h>
int main()
{
int a = 5 * 3 % 6 - 8 + 3;
printf("%d", a);
return 0;
}

36
Q7. What is the output of this program?
#include <stdio.h>
int main()
{
float b = 3 % 0 * 1 - 4 / 2;
printf("%f", b);
return 0;

}
Q8. What is the output of this program?
#include <stdio.h>
int main()
{
float b = 5 % 3 & 4 + 5 * 6;
printf("%f", b);
return 0;
}

37
Q 9. What is the output of this statement?
printf ( "%d" , printf ( “welcome" ) );

Q 10. Program to display the product of two float numbers


#include <stdio.h>
int main(){
float num1, num2, product;
printf("Enter first Number: ");
scanf("%f", &num1);
printf("Enter second Number: ");
scanf("%f", &num2);
product = num1 * num2;
printf("Product of entered numbers is:%.3f", product);
return 0;
}

38
Q 11. What is the output of the following program?
#include<stdio.h>
int main();
void main()
{
printf(“okay”);
}

Q 12. Point out the errors in the following codes:


#include <stdio.h>
int main()
{
printf(Hello);
return 0;
}

39
Q 13. Point out the errors in the following codes:
#include <stdio.h>
int main()
{
printf("Hello\n");
return 0;
}
Q 14. Point out the errors in the following codes:
#include <stdio.h>
int main()
{
printf("Hello")
return 0
}

40
Q 15. Point out the errors in the following codes:
int main()
{
printf(Hello);
return 0;
}

41

You might also like