[go: up one dir, main page]

0% found this document useful (0 votes)
29 views127 pages

TCS - D3-S2

The document contains a series of multiple-choice questions (MCQs) related to the C programming language, covering topics such as keywords, output of programs, variable declarations, and function return types. Each question is presented with four answer options, and the correct answer is provided for each question. The document serves as a study guide for understanding fundamental concepts in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views127 pages

TCS - D3-S2

The document contains a series of multiple-choice questions (MCQs) related to the C programming language, covering topics such as keywords, output of programs, variable declarations, and function return types. Each question is presented with four answer options, and the correct answer is provided for each question. The document serves as a study guide for understanding fundamental concepts in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 127

AMITopic/Course

Sub-Topic (Example: name of college)

MCQs
Question 1
All keywords in C are in

A) Upper case letter


B) Lower case letter
C) Camel case letter
D) None of the above
Question 1
All keywords in C are in

A) Upper case letter


B) Lower case letter
C) Camel case letter
D) None of the above

Ans: B
Question 2
What will be the output of the program?

#include<stdio.h>
int main()
{
int k=5,*p=&k,**m =&p;
printf("%d%d%d\n",k,*p,**p);
}

A)555 B) 55junk C) 5junkjunk D) Error


Question 2
What will be the output of the program?

#include<stdio.h>
int main()
{
int k=5,*p=&k,**m =&p;
printf("%d%d%d\n",k,*p,**p);
}

A)555 B) 55junk C) 5junkjunk D) Error


Ans: D
Question 3
In the standard library of C programming language, which of the
following header file is designed for basic mathematical
operations?

A) stdio.h
B) conio.h
C) math.h
D) dos.h
Question 3
In the standard library of C programming language, which of the
following header file is designed for basic mathematical
operations?

A) stdio.h
B) conio.h
C) math.h
D) dos.h

Ans: C
Question 4
Which of the following is a collection of different data types?

A) String
B) Structure
C) Array
D) Files
Question 4
Which of the following is a collection of different data types?

A) String
B) Structure
C) Array
D) Files

Ans: B
Question 5
Strings are character arrays. The last index of it contains

A) \t
B) \0
C) \n
D) \1
Question 5
Strings are character arrays. The last index of it contains

A) \t
B) \0
C) \n
D) \1
Ans: B
Question 6
Which of the following uses structure?

A) Linked Lists
B) Graphs
C) Binary Tree
D) All of the above
Question 6
Which of the following uses structure?

A) Linked Lists
B) Graphs
C) Binary Tree
D) All of the above

Ans: D
Question 7
What will be the output of the program?

#include<stdio.h>
int main()
{
double x=0;
for(;x<2.0;x++)
{
printf("Hello");
}
return 0;
}

A) HelloHello B) Hello C) Runtime D) None


Error
Question 7
What will be the output of the program?

#include<stdio.h>
int main()
{
double x=0;
for(;x<2.0;x++)
{
printf("Hello");
}
return 0;
}

A) HelloHello B) Hello C) Runtime D) None


Ans: A Error
Question 8
What will be the output of the program?

#include<stdio.h>
int main()
{
static int i=3;
if(--i)
{
main();
printf("Hello");
}
}

A) HelloHello B) Hello C) Runtime D) None


Error
Question 8
What will be the output of the program?

#include<stdio.h>
int main()
{
static int i=3;
if(--i)
{
main();
printf("Hello");
}
}

A) HelloHello B) Hello C) Runtime D) None


Ans: A Error
Question 9
What will be the output of the program?

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

A) HelloHi B) Hello C) Runtime D) None


Error
Question 9
What will be the output of the program?

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

A) HelloHi B) Hello C) Runtime D) None


Ans: A Error
Question 10
What will be the output?

#include<stdio.h> int main()


#include<string.h> {
#include<stdlib.h> char *str=(char*)malloc(64);
void myfunc (char**param) strcpy(str,"hello");
{ myfunc(&str);
++param; myfunc(&str);
} printf("%s\n",str);
return 0;
}

A) hello B) ello C) llo D) lo


Question 10
What will be the output?

#include<stdio.h> int main()


#include<string.h> {
#include<stdlib.h> char *str=(char*)malloc(64);
void myfunc (char**param) strcpy(str,"hello");
{ myfunc(&str);
++param; myfunc(&str);
} printf("%s\n",str);
return 0;
}

A) hello B) ello C) llo D) lo


Ans: A
Question 11
The keyword ‘break’ cannot be simply used within

A) do-while
B) if-else
C) for
D) while
Question 11
The keyword ‘break’ cannot be simply used within

A) do-while
B) if-else
C) for
D) while
Ans: B
Question 12
Which for loop has range of similar indexes of ‘i’ used in
for(i=0;i<n;i++)

A) for(i=n;i>0;i--)
B) for(i=n;i>=0;i--)
C) for(i=n-1;i>0;i--)
D) for(i=n-1;i>=0;i--)
Question 12
Which for loop has range of similar indexes of ‘i’ used in
for(i=0;i<n;i++)

A) for(i=n;i>0;i--)
B) for(i=n;i>=0;i--)
C) for(i=n-1;i>0;i--)
D) for(i=n-1;i>=0;i--)
Ans: D
Question 13
What type of array is generally generated in Command-line
argument?

A) Multi Dimensional Array


B) Jagged Array
C) 2-Dimensional Array
D) Single Dimensional Array
Question 13
What type of array is generally generated in Command-line
argument?

A) Multi Dimensional Array


B) Jagged Array
C) 2-Dimensional Array
D) Single Dimensional Array
Ans: B
Question 14
The maximum length of the command-line arguments including
the spaces is

A) May vary from one OS to another


B) 256 characters
C) Depends on the Number of arguments
D) 128 characters
Question 14
The maximum length of the command-line arguments including
the spaces is

A) May vary from one OS to another


B) 256 characters
C) Depends on the Number of arguments
D) 128 characters

Ans: A
Question 15
The index of the last argument in command line arguments is

A) argc
B) argc * 2
C) argc – 1
D) argc + 1
Question 15
The index of the last argument in command line arguments is

A) argc
B) argc * 2
C) argc – 1
D) argc + 1
Ans: C
Question 16
What is the output of this C code?

#include<stdio.h>
void m();
void main()
{
void m()
{
printf("SimpleWay2Code");
}
}
A Simple Way 2 Code
)

B Compile time error


)

C No output
)

D Varies
)
A Simple Way 2 Code
)

B Compile time error


)

C No output
)

D Varies
)

Ans: C
Question 17
What is the output of this C code?

#include<stdio.h>
void main()
{
static int x=3;
x++;
if(x<=5)
{
printf("hello");
main();

}
}
A Run time error
)

B hello
)

C Infinite hello
)

D hellohello
)
A Run time error
)

B hello
)

C Infinite hello
)

D hellohello
)

Ans: D
Question 18
Which of the following is not valid variable name declaration?

A) int __v1;
B) int __1v;

C) int __V1;

D) None
Question 18
Which of the following is not valid variable name declaration?

A) int __v1;
B) int __1v;

C) int __V1;

D) None

Ans: D
Question 19
Which of the following is not a valid variable name declaration?

A) int _v1;
B) int v_1;

C) int 1_v;

D) int _1v;
Question 19
Which of the following is not a valid variable name declaration?

A) int _v1;
B) int v_1;

C) int 1_v;

D) int _1v;

Ans: C
Question 20
Variable names beginning with underscore is not encouraged.
Why?

A) It is not standard form


B) To avoid conflicts since assemblers and loaders use such
names
C) To avoid conflicts since library routines use such names

D) To avoid conflicts with environment variables of an operating


system
Question 20
Variable names beginning with underscore is not encouraged.
Why?

A) It is not standard form


B) To avoid conflicts since assemblers and loaders use such
names
C) To avoid conflicts since library routines use such names

D) To avoid conflicts with environment variables of an operating

Ans: Csystem
Question 21
Which is not a valid C variable name?

A) int number;
B) float rate;

C) int variable_count;

D) int $main
Question 21
Which is not a valid C variable name?

A) int number;
B) float rate;

C) int variable_count;

D) int $main
Ans: D
Question 22
Which of the following is true for variable names in C?
A They can contain alphanumeric characters as well as special
) characters

B It is not an error to declare a variable to be one of the keywords


) (likegoto,static)

C Variable names can’t start with a digit


)

D Variable can be of anylength


)
A They can contain alphanumeric characters as well as special
) characters

B It is not an error to declare a variable to be one of the keywords


) (likegoto,static)

C Variable names can’t start with a digit


)

D Variable can be of anylength


)

Ans : C
Question 23
What will be the output for the program?

#include<stdio.h>
int main()
{
int main=5;
printf(“%d”,main);
return0;
}
A compile-time error
)

B run-time error
)

C Run without any error and prints 5


)

D Experience infinite looping


)
A compile-time error
)

B run-time error
)

C Run without any error and prints 5


)

D Experience infinite looping


)

Ans: C
Question 24
Which of the following cannot be a variable name in C?

A) friend
B) true

C) volatile

D) export
Question 24
Which of the following cannot be a variable name in C?

A) friend
B) true

C) volatile

D) export

Ans: C
Question 25
The format identifier ‘%i’ is also used for_____ datatype?

A) char
B) double

C) float

D) int
Question 25
The format identifier ‘%i’ is also used for_____ datatype?

A) char
B) double

C) float

D) int

Ans: D
Question 26
What is short int in C programming?

A) Basic data type of C


B) Qualifier

C) Short is the qualifier and int is the basic data type

D) All of the mentioned


Question 26
What is short int in C programming?

A) Basic data type of C


B) Qualifier

C) Short is the qualifier and int is the basic data type

D) All of the mentioned

Ans: C
Question 27
What is the return-type of the function sqrt()?

A) int
B) float
C) double
D) Depends on the data type of the parameter
Question 27
What is the return-type of the function sqrt()?

A) int
B) float
C) double
D) Depends on the data type of the parameter
Ans: C
Question 28
What is the output of this code having void return-type function?

#include<stdio.h>
void foo()
{
return 1;
}
void main()
{
int x=0;
x=foo();
printf("%d",x);
}
A 1
)

B 0
)

C Run time error


)

D Compile time error


)
A 1
)

B 0
)

C Run time error


)

D Compile time error


)

Ans: D
Question 29
What is the output of this code having void return-type function?

#include<stdio.h>
void main()
{
int k=m();
printf("%d",k);
}
void m()
{
printf("hello");
}
A hello5
)

B Error
)

C Nothing
)

D Garbage value
)
A hello5
)

B Error
)

C Nothing
)

D Garbage value
)

Ans: A
Question 30
The output of the code below is

#include<stdio.h>
int *m()
{
int *p=5;
return p;
}
void main()
{
int *k=m();
printf("%d",k);
}
A 5
)

B Junk value
)

C 0
)

D Error
)
A 5
)

B Junk value
)

C 0
)

D Error
)

Ans: A
Question 31
The output of the code below is

#include<stdio.h>
int main()
{
int i=1;
if(!i)
printf("SimpleWay2Code,");
else
{
i=0;
printf("C-Program");
main();
}
return 0;
}
A Prints “SimpleWay2Code, C-Program” infinitely
)

B Prints “C-Program” infinitely


)

C Prints “C-Program, SimpleWay2Code” infinitely


)

D Error: main() should not inside else statement


)
A Prints “SimpleWay2Code, C-Program” infinitely
)

B Prints “C-Program” infinitely


)

C Prints “C-Program, SimpleWay2Code” infinitely


)

D Error: main() should not inside else statement


)

Ans: B
Question 32
How many times the program will print “SimpleWay2Code”?

#include<stdio.h>
int main()
{
printf("SimpleWay2Code");
main();
return 0;
}
A Infinite times
)

B 32767 times
)

C 65535 times
)

D Till stack overflows


)
A Infinite times
)

B 32767 times
)

C 65535 times
)

D Till stack overflows


)

Ans: D
Question 33
What will be the output?

#include<stdio.h>
int main()
{
int a=5,b=7;
switch(a)
{
case 5:print("I am 5");
break
case b:printf("I am not 5");
break
default:print("I am different“);
}
return 0;
}
A I am 5
)

B I am not 5
)

C I am different
)

D Error
)
A I am 5
)

B I am not 5
)

C I am different
)

D Error
)

Ans: D
Question 34
Ashima wants to print a pattern which includes checking and
changing a variables value iteratively so she decides to use a
loop/condition. Which of the following options should she use such
that the body of the loop/condition is executed atleast once
whether the variable satisfies the entering condition or not?
A For Loop
)

B While Loop
)

C Do while Loop
)

D Switch case
)
A For Loop
)

B While Loop
)

C Do while Loop
)

D Switch case
)

Ans: C
Question 35
The construct “if(condition) then A else B” is for which of the
following purposes?

A) Decision Making
B) Iteration
C) Recursion
D) Object Oriented Programming
Question 35
The construct “if(condition) then A else B” is for which of the
following purposes?

A) Decision Making
B) Iteration
C) Recursion
D) Object Oriented Programming

Ans: A
Question 36
Ravi and Rupali are asked to write a program to sum the rows of
2X2 matrices stored in the array A . Ravi writes the following code
(CodeA): for n=0 to 1 sum Row1[n]=A[n][1]+A[n][2] end
Rupali writes the following code
(CodeB): sum Row1[0]=A[0][1]+A[0][2]
Sum Row1[1]=A[1][1]+A[1][2]
Comment upon these codes ( Assume no loop¬ unrolling done by
compiler):
A Code A will execute faster than Code B.
)

B Code B will execute faster than Code A.


)

C Code A is logically incorrect.


)

D Code B is logically incorrect.


)
A Code A will execute faster than Code B.
)

B Code B will execute faster than Code A.


)

C Code A is logically incorrect.


)

D Code B is logically incorrect.


)

Ans: B
Question 37
The correct syntax for running two variable for loop simultaneously
is.

A) for(i=0;i<n;i++) for(j=0;j<n;j+=5)
B) for(i=0,j=0;i<n,j<n;i++,j+=5)
C) for(i=0;i<n;i++){}
D) for(j=0;j<n;j++){}
Question 37
The correct syntax for running two variable for loop simultaneously
is.

A) for(i=0;i<n;i++) for(j=0;j<n;j+=5)
B) for(i=0,j=0;i<n,j<n;i++,j+=5)
C) for(i=0;i<n;i++){}
D) for(j=0;j<n;j++){}

Ans: B
Question 38
‘for(;;)’ represents an infinite loop. It can be terminated by

A) break
B) return
C) exit
D) All
Question 38
‘for(;;)’ represents an infinite loop. It can be terminated by

A) break
B) return
C) exit
D) All

Ans: D
Question 39
What will be the output of the program?

#include<stdio.h>
int main()
{
static int i;
printf("%d",i);
return 0;
}

A) 0 B) 1 C) Runtime D) Garbage
Error value
Question 39
What will be the output of the program?

#include<stdio.h>
int main()
{
static int i;
printf("%d",i);
return 0;
}

A) 0 B) 1 C) Runtime D) Garbage

Ans: A Error value


Question 40
What will be the output of the program?

#include<stdio.h>
int *i;
int main()
{
if(i==NULL)
{
printf("True");
}
return 0;
}

A) True B) No output C) Error D) Invalid


Question 40
What will be the output of the program?

#include<stdio.h>
int *i;
int main()
{
if(i==NULL)
{
printf("True");
}
return 0;
}

A) True B) No output C) Error D) Invalid


Ans: A
Question 41
What will be the output of the program?

#include<stdio.h>
static int x=5;
int main()
{
x=9;
{
int x=4;
}
printf("%d",x);
}

A) 9 B) 4 C) Error D) 5
Question 41
What will be the output of the program?

#include<stdio.h>
static int x=5;
int main()
{
x=9;
{
int x=4;
}
printf("%d",x);
}

A) 9 B) 4 C) Error D) 5

Ans: A
Question 42
What will be the output?

#include<stdio.h> else if(m>i)


int main() {
{ printf("Hi");
int i=0.7; }
static float m=0.7; else
if(m==i) {
{ printf("HelloHi");
printf("Hello"); }
} return 0;
}

A) hello B) HelloHi C) Hi D) Error


Question 42
What will be the output?

#include<stdio.h> else if(m>i)


int main() {
{ printf("Hi");
int i=0.7; }
static float m=0.7; else
if(m==i) {
{ printf("HelloHi");
printf("Hello"); }
} return 0;
}

A) hello B) HelloHi C) Hi D) Error


Ans: C
Question 43
Which of this is used to skip one iteration?

A) break

B) continue

C) goto

D) return
Question 43
Which of this is used to skip one iteration?

A) break

B) continue

C) goto

D) return
Ans: B
Question 44
Which of the following does not require to include math.h header
file?

A) pow()

B) rand()

C) sqrt()

D) sinh()
Question 44
Which of the following does not require to include math.h header
file?

A) pow()

B) rand()

C) sqrt()

D) sinh()

Ans: B
Question 45
The scope of an automatic variable is:

A) Within the block it appears

B) With in the blocks of the block it appears

C) Until the end of program

D) With in the block it appears & Within the blocks of the block it
appears
Question 45
The scope of an automatic variable is:

A) Within the block it appears

B) With in the blocks of the block it appears

C) Until the end of program

D) With in the block it appears & Within the blocks of the block it

Ans: D appears
Question 46
Automatic variables are allocated space in the form of a:

A) stack

B) queue

C) Priority queue

D) random
Question 46
Automatic variables are allocated space in the form of a:

A) stack

B) queue

C) Priority queue

D) random

Ans: A
Question 47
Which of the following is a storage specifier?

A) enum

B) union

C) auto

D) volatile
Question 47
Which of the following is a storage specifier?

A) enum

B) union

C) auto

D) volatile

Ans: C
Question 48
What will be the output?

#include<stdio.h>
int main()
{
int a=456,b,c,d=10;
b=a/d;
c=a-b;
printf("%d",c);
return 0;
}
A 411.4
)

B 411
)

C 410.4
)

D 410
)
A 411.4
)

B 411
)

C 410.4
)

D 410
)

Ans: B
Question 49
What is the output of this C code?

#include<stdio.h>
int main()
{
register int i=10;
int*q=&i;
*q=11;
printf(“%d%d\n”,i,*q);
}
A Depends on whether “i” is actually stored in machine register
)

B 10 10
)

C 11 11
)

D Compile time error


)
A Depends on whether “i” is actually stored in machine register
)

B 10 10
)

C 11 11
)

D Compile time error


)

Ans: D
Question 50
Register storage class can be specified to global variables

A) true

B) false

C) Depends on the compiler

D) Depends on the standard


Question 50
Register storage class can be specified to global variables

A) true

B) false

C) Depends on the compiler

D) Depends on the standard

Ans: B
Question 51
Register variables reside in

A) stack

B) registers

C) heap

D) Main memory
Question 51
Register variables reside in

A) stack

B) registers

C) heap

D) Main memory

Ans: B
Question 52
Which of the following operation is not possible in a register
variable?

A) Reading the value into a register variable

B) Copy the value from a memory variable

C) Global declaration of register variable

D) All of the mentioned


Question 52
Which of the following operation is not possible in a register
variable?

A) Reading the value into a register variable

B) Copy the value from a memory variable

C) Global declaration of register variable

D) All of the mentioned

Ans: B
Question 53
What is the output of this C code?

#include<stdio.h>
int a ;
void main( )
{
if(a)
printf(“Hello”);
else
printf(“world”);
}
A Hello
)

B World
)

C compile time error


)

D None of the mentioned


)
A Hello
)

B World
)

C compile time error


)

D None of the mentioned


)

Ans: B
Question 54
What is the output of this C code?

#include<stdio.h>
void main( )
{
int a=5;
if(true);
printf(“hello”);
}
A It will display hello
)

B It will throw an error


)

C No Output
)

D Depends on Compiler
)
A It will display hello
)

B It will throw an error


)

C No Output
)

D Depends on Compiler
)

Ans: B
THANK YOU

You might also like