C-TEST
01. Which one of the following declarations is correct?
Ans : int length;
02. What is
the output of the following program?
#include<stdio.h>
int main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {"Tiger"};
printf("%d, %f", e.age, e.sal);
return 0;
}
Ans : 0, 0.000000
03. What
will be the output of the following program?
#include<stdio.h>
int main()
{
int
x = 10, y = 20;
if(x+y > y)
printf("x = %d\n", x);
else
printf("y = %d", y);
return 0;
}
Ans : x = 10
04. We
declare a function with ______ if it does not have any return type.
Ans : void
05. What
will be the output of the following program?
#include<stdio.h>
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf("c=%d", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
Ans : Will give a compile error
06. Which of the following is the correct
postfix operation?
Ans : a++
07. Which
of the following marks the end of executable statements?
Ans : return 0;
08. What
will be the output of the following program?
#include<stdio.h>
int X=40;
int main()
{
int X=20;
printf("%d", X);
return 0;
}
Ans : 20
09. Which
keyword is used to transfer control from a function back to the calling
function?
Ans : return
10. What
does the return 0; statement in main function indicate?
Ans : The program worked as expected, without any errors during
its execution
11. Which
of the following functions should not use a return statement?
Ans : void
12. What
will be the output of the following C program?
#include<stdio.h>
int main()
{
int arr[1]={10};
printf("%d", arr[0]);
return 0;
}
Ans : 10
13. What
will be the output of the following program?
#include<stdio.h>
int main()
{
int i = 5;
while(i-- >= 0)
printf("%d,", i);
i = 5;
printf("\n");
while(i-- >= 0)
printf("%i,", i);
while(i-- >= 0)
printf("%d,", i);
return 0;
}
Ans : 4, 3, 2, 1, 0, -1
4, 3, 2, 1, 0, -1
14. What
will be the output of the following program?
#include<stdio.h>
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf("%d", c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
else
return 10;
}
Ans : 100
15. What
does a logical operator return for a true condition?
Ans : 1
16. Point
out the error line in the following program.
1.
#include<stdio.h>
2. int
main()
3. {
4. void v = 0;
5. printf("%d", v);
6. return 0;
7. }
Ans : Line number 4
17. Point
out the error line in the following program.
1.
#include<stdio.h>
2.
#include<string.h>
3. int main()
4. {
5. static char str1[] = "Welcome";
6. static char str2[20];
7. static char str3[] = "Sir";
8. str2 = strcpy(str3, str1);
9. printf("%s\n", str2);
10. return 0;
11. }
Ans : Line number 8
18. What
will be the output of the program? Type the answer with the correct case.
#include<stdio.h>
int main()
{
char str[6] = "India ";
printf("%s",str);
return 0;
}
Ans : India
19. Which
of the following format specifiers is used to provide exactly 4 digits after
decimal point?
Ans : %.4f
20. What
will be the output of the following program?
#include<stdio.h>
int main()
{
int fun(int);
int i = fun(10);
printf("%d\n", --i);
return 0;
}
int fun(int i)
{
return (i++);
}
Ans : 9
21. What is the purpose of namespace?
Ans : To avoid name collisions
22. What
will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf("b = %d c = %d", b, c);
return 0;
}
Ans : b = 100 c = 200
23. What
will be the output of the following C program?
#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
Ans : 6, 6
24. Which
of the following cannot be checked in a switch-case statement?
Ans : Float
25. Which
of the following operators will give the remainder after dividing 3 by 2?
Ans : %
26. Point
out the error line in the following program.
1.
#include<stdio.h>
2.
int main()
3. {
4.
int i = 1;
5.
switch(i)
6.
{
7.
printf("This is c program.");
8.
case 1:
9. printf("Case1");
10.
break;
11.
case 2
12. printf("Case2");
13. break;
14.
}
15.
return 0;
16.
}
Ans : Line number 11
27. Select
the missing code lines from the dropdown provided.
The C code
given below should print the sum of digits of a number entered by the user.
But, line
numbers 6 and 10 are missing.
1.
#include<stdio.h>
2. int
main()
3. {
4. int num, sum=0, rem;
5. printf("Enter a number\n");
6. ---------------Missing
code -------------------
7. while(num>0)
8. {
9. rem = num%10;
10. ---------------Missing
code -------------------
11. num = num/10;
12. }
13. printf("Sum is %d\n", sum);
14. return 0;
15. }
Ans :-
Line
6 : scanf("%d", &num);
Line
10 : sum = sum+rem;
28. If
originally x=10, what is the value of the expression:
--x;
Ans : 9
29. What
will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 300, b, c;
if(a >= 400)
b = 300;
c = 200;
printf("%d,%d", a, c);
return 0;
}
Ans : 300,200
30. What
will be the output of the following C program?
#include<stdio.h>
int main()
{
char t;
char *p1 = "Spoken", *p2;
p2=p1;
p1 = "Tutorial";
printf("%s %s", p1, p2);
return 0;
}
Ans : Tutorial Spoken
31. What
will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 7;
if(a%6)
printf("Hi");
else
printf("Hello");
return 0;
}
Ans : Hi
32. If x=10
and sum=0, what is the value of sum after we execute sum=++x?
Ans : 11
33. What
will be the output of the following program?
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
Ans : Hello Hi
34. What
will be the output of the following C program?
#include<stdio.h>
void fun(int*, int*);
int main()
{
int i=5, j=2;
fun(&i, &j);
printf("%d, %d", i, j);
return 0;
}
void fun(int *i, int *j)
{
*i = *i**i;
*j = *j**j;
}
Ans : 25, 4
35. Which
of the following is the correct way of writing a comment in C?
Ans : /* Comment */
36. What is
the variable called that is declared outside all the functions?
Ans : Global variable
37. What is
the range of a character variable?
Ans : -128 to 127
38. What is
the format specifier for double data-type?
Ans : %lf
39. What
will be the output of the following C program?
#include<stdio.h>
int main()
{
int a[5] = {5, 3, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
Ans : 5, 4, 25
40. Which
of the following keywords is used to create a string?
Ans : char
41. How
many cases a switch statement can have?
Ans : Any number
42. What
will be the output of the following C program?
#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
Ans
: 6, 6
43. What
will be output on execution of the following C code?
#include<stdio.h>
int main()
{
int a=11;
printf("%d",a);
return 0;
}
Ans : 11
44. What
will be output of the following c program?
#include<stdio.h>
int xyz=10;
int main(){
int xyz=20;
printf("%d",xyz);
return 0;
}
Ans : c. 20
45. What
will be the output of the program? Write
the answer in digits not alphabets.
#include<stdio.h>
int main()
{
int a=2,b=6,c;
c = a%b;
printf("%d",c);
return 0;
}
Ans : 2
46. What
will be the output of the program? Type the answer with the correct case.
#include<stdio.h>
int main()
{
printf("nn/n/nnn/n");
return 0;
}
Ans : nn/n/nnn/n
8 comments:
Mind blowing
Good jobπ
Thanks bhai π
Keep going thanks ❤πΉ
Thanks❤
Thank you❤π
Niceππ
Keep it up broo π₯°π₯°
Post a Comment