0% found this document useful (0 votes)
115 views17 pages

C Q.

The document contains 32 multiple choice questions about C programming concepts such as variables, data types, operators, functions, arrays, loops, conditional statements, strings and more. The questions test understanding of basic syntax, evaluating expressions, analyzing code snippets, predicting output, finding errors and completing code with missing lines.

Uploaded by

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

C Q.

The document contains 32 multiple choice questions about C programming concepts such as variables, data types, operators, functions, arrays, loops, conditional statements, strings and more. The questions test understanding of basic syntax, evaluating expressions, analyzing code snippets, predicting output, finding errors and completing code with missing lines.

Uploaded by

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

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

#include<stdio.h>
int main()
{
char ch;
if(ch = printf(""))
printf("It matters");
else
printf("It doesn't matter");
return 0;
}

Select one:
matter
o No output
o It matters
o It doesn't matter
o Question 2

2. Which function is used to read data from the console?


Select one:
o main()
o if
o scanf()
o cout

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


#include<stdio.h>
int main()
{
char j=1;
while(j < 5)
{
printf("%d, ", j);
j = j+1;
}
printf("\n");
return 0;
}

Select one:
o 1, 2, 3, 4,
o 23456
o 1234
o 4, 3, 2, 1

4. What will be the output of the following C program?


#include<stdio.h>
int main()
{
char str[] = "Nagpur";
str[0]='K';
printf("%s, ", str);
str = "Kanpur";
printf("%s", str+1);
return 0;
}
Select one:
o Nagpur, Kanpur
o Kagpur, anpur
o Error
o Kagpur, Kanpur

5. The result of a relational operation is always:


Select one:
o Always False
o All of these
o Always True
o Either True or False

6. Which of the following statements is true?


Select one:
o The later changes on variable b will affect the value of variable a.
o The value of b is assigned to variable a. The later changes on variable b will
not affect the value of variable a.
o The variable a and the variable b have same memory address.
o The value of variable a is assigned to variable b.

7. What will be output on execution of the following C code?


#include<stdio.h>
int main()
{
int a=11;
printf("%d",a);
return 0;
}
Select one:
o -2
o 2
o 0
o 11

8. What does the conditional statement control?


Select one:
o operators
o main function
o arguments
o flow of program execution

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


#include<stdio.h>
int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B';
a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}
Select one:
o BC
o No output
o CD
o AB

10.Which of the following is used to comment a single-line in a C Program?


Select one:
o /*
o //
o */
o +/

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


#include<stdio.h>
int main()
{
int i=0;
for(; i<=5; i++);
printf("%d", i);
return 0;
}
Select one:
o 6
o 0, 1, 2, 3, 4, 5
o 1, 2, 3, 4
o 5

12.If originally x=10, what is the value of the expression:


--x;
Select one:
o 0
o 11
o 9
o 10

13.What is the statement terminator in C?


Select one:
o /
o ;
o *
o &

14.Which of the following variable is enclosed in single quotes?


Select one:
o boolean
o integer
o character
o float

15.What will be the output of the following C program?


#include <stdio.h>
int main()
{
char star[10]="HelloWorld";
printf("%c\n",star[5]);
return 0;
}

Select one:
o w
o e
o W
o Error

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


#include<stdio.h>
int main()
{
int i;
int j = 2;
for(i=1; i<=j; i++)
{
printf("%d", ++i);
}
return 0;
}

Select one:
o 2
o 0
o 1
o 3
17.What is the command to compile a C program named welcome.c?
Select one:
o welcome.c
o tcc welcome
o gcc welcme.c
o gcc welcome.c

18.How many times will "India" be printed in the following program?


#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("India");
}
return 0;
}

Select one:
o 0 times
o Infinite times
o 11 times
o 10 times
19.In the following statements, what does 6 specify?
int num[6];
num[6]=21;
Select one:
o In the first statement, 6 specifies a particular element, whereas in the second
statement it specifies an array size.
o In the first statement, 6 specifies a particular element, whereas in the second
statement it specifies a type.
o In the first statement, 6 specifies an array size, whereas in the second
statement it specifies a particular element of an array.
o In both the statements, 6 specifies an array size.

20.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;
}
Select one:
o 30
o 20
o None of these
o Compilation Error

21.What will be the output of the following C program?

#include<stdio.h>
int main()
{
static char s[25] = "Hello world";
int i=0;
char ch;
ch = s[++i];
printf("%c", ch);
ch = s[i++];
printf("%c", ch);
ch = s[i++];
printf("%c", ch);
return 0;
}

Select one:
o eel
o hel
o ell
o eee

22.What will be the output of the following C program?


#include<stdio.h>
int main()
{
char c;
c = 'A';
printf("%c",c);
return 0;
}
Select one:
o c
o A
o a
o 65
23.Point out the error line in the following program.
1. #include<stdio.h>
2. #include<string.h>
3. int main()
4. {
5. int i;
6. char str1[] = "Welcome";
7. char str3[] = "Sir";
8. if(i=strcmp(str3, str1);)
9. printf("%d\n", i);
10. return 0;
11. }

Select one:
o Line number 8
o Line number 7
o None of these
o Line number 9

24.Point out the error line in the following program.


1. #include<stdio.h>
2. int main()
3. {
4. int i=1,j=1;
5. if(i=j)
6. {
7. printf("i=j");
8. }
9. else
10. {
11. printf("Not Equal");
12. }
13. }
Select one:
o Line number 5
o Line number 4
o Line number 7
o None of these

25.Which of the following function(s) can NOT be used to find the length of a
string?
Tick all correct answer(s). No partial marks and no negative marks.
Select one or more:
o int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
{ length++; s++; }
return (length);
}
o int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
s++;
return (length);
}
o int xstrlen(char s)
{
int length=0;
while(*s!='\0')
length++; s++;
return (length);
}
o int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
length++;
return (length);
}

26.Which of the following is/are valid expression(s)? Tick all correct answer(s).
No partial marks and no negative marks.
Select one or more:
o None of these
o a = 2 + (b = 5);
o a = 11 % 3
o a = b = c = 5;
27.Which of the following operation(s) is/are correct? Tick all correct answer(s).
No partial marks and no negative marks.
Select one or more:
o long int k = 365L; k = k;
o float a = 3.14; a = a%3;
o short int j = 255; j = j;
o int i = 35; i = i%5;

28.Select the missing code lines from the dropdown provided.


The C code given below should check whether the number entered by the user
is Negative, Positive or Zero.
But, line numbers 9 and 11 are missing.
1. #include <stdio.h>
2. int main()
3. {
4. int num;
5. printf("Enter a number: ");
6. scanf("%d",&num);
7. if (num<0)
8. printf("%d is negative.",num);
9. ---------------Missing code -------------------
10. printf("%d is positive.",num);
11. ---------------Missing code -------------------
12. printf("You entered zero.");
13. return 0;
14. }
o Line 9
o Line 11

29.Select the missing code lines from the dropdown provided.


The C code given below should count digits of a number entered by the user.
But, line numbers 7 and 9 are missing.
1. #include <stdio.h>
2. int main()
3. {
4. int num,count=0;
5. printf("Enter an integer: ");
6. scanf("%d", &num);
7. ---------------Missing code -------------------
8. {
9. ---------------Missing code -------------------
10. ++count;
11. }
12. printf("Number of digits: %d",count);
13. }
o Line 7
o Line 9

30.Select the missing code lines from the dropdown provided.


The C code given below shpould check whether the number entered by the user
is a prime number or not.
But, line numbers 9 and 15 are missing.
1. #include<stdio.h>
2. int main()
3. {
4. int num, i;
5. printf("Enter a number\n");
6. scanf("%d", &num);
7. for(i=2; i<=num-1; i++)
8. {
9. ---------------Missing code -------------------
10. {
11. printf("%d is not a prime number\n", num);
12. break;
13. }
14. }
15. ---------------Missing code -------------------
16. {
17. printf("%d is a prime number\n", num);
18. }
19. return 0;
20. }
Line
o Answer
o Answer

31.What will be the output of the following program? Type the answer with the
correct Case.
#include<stdio.h>
int main()
{
char *ptr;
char string[]="How are you?";
ptr=string;
ptr+=4;
printf("%s",ptr);
return 0;
}
Answer:

32.What will be the output of the program? Write the answer in digits not
alphabets.
#include<stdio.h>
int main()
{
float a=3.16000;
printf("%.2f", a);
return 0;
}

Answer:

You might also like