WorksheetsC Programming MCQ
Total questions: 118
Worksheet time: 2hrs 42mins
Which one of the following languages is predecessor to C programming language?
A.
B.
C++.
Java.
Which of the following symbol is used to denote a preprocessor statement?
#
;
!
~
C is a/an __________ language.
High –level
Low - level
Middle –level
Assembly
________ reserves all keywords C language
Compiler
Interpreter
Header file
None
Which one of the statements is not valid with respect to low level language?
Set of instructions in the form of sequences of zeros and ones.
It is machine- dependent.
It is confined to the configuration of the computer.
It is easy to identify the commands of a low level language.
A switch statement is used to ________
Switch between function in a program.
Switch form one variable to another variable.
Choose from multiple possibilities which may arise due to different values of a single variable.
Switching between variable and statements.
A character array always ends with a/an ________.
Null('\0') character
Question mark(?)
Full stop(.)
Asterisk*
Arrays cannot be initialized if they are (a)
Every C program must at least contain ______ function(s).
Only one
Only two
Must contain one
One or more
Information will be passed to the function via special identifiers called _______.
Argument
Parameters
Variable
None
Which of the following functions(s) return(s) multiple values?
Printf()
Scanf()
Printf() & scanf()
Fprintf()
Explain the following pointer declaration int *p.
P is a pointer
p is a pointer to an integer quantity
*p is a pointer
*p is a pointer to an integer quantity
C programs are converted into machine language with the help of
An Editor
A compiler
An operating system
None of these.
C was primarily developed as
System programming language
General purpose language
Data processing language
None of the above.
What will be the output of the following program? main() { system(" "); }
control goes to the dos prompt.
syntax error
Bad command or file name
What will be the output of the following program? main() { printf("\n%d%d%d%d",'A','B','C','D'); }
ABCD.
65666768.
91929394.
Error.
which one of the following functions is appropriate for accepting a string?
gets()
getch()
getche()
scamf()
preprocessor directives follow the following syntax rule_________.
Begin with # and end with semi-colon.
End with semi-colon.
Begin with # and do not require a semi-colon.
They must be include within<>
consider the following code: #define M 5 total=*value; printf("M=%d\n",M); the two lines would be changed dring preprocessing as follows:
total=M*value; printf("M=%d\n",M);
total=5*value; printf("M=%d\n",M);
total=5*value; printf("5=%d\n",M);
total = 5*value; printf("M=%d\n",5)
which of the following directives is equivalent to #ifdef
#Ifdefine
#Ifdefined()
#Ifdef()
#If
Which one of the following is not a reserved keyword for C?
auto
case
main
default
which one of the following statements is false with respect to the sequential
The sequential files can grow or shrink dynamically.
The records can be accessed sequentially.
It has a fixed, predetermined number of components.
It is a data structure which consists of the sequence of records of the same type and size.
in “C” language it is assumed that input data appears as_______
A stream.
ASCII characters.
bits.
English alphabets.
Which of the following is/are invalid variable(s)?
interest paid
si-int
AVERAGE
Both(b)and(d) of the above.
Which one of the following C statement is not valid?
int= 314.562*150
si=principal*rateofinterest*number of years/100
k=a*b+c(2.5a+b);
None
Which one of the following C statements represent the given formula? z= [8.8(a+b)2/c]/[0.5+2a/(q+r)] [ (a+b)*(1/m) ]
z=((8.8(a+b)*2/c)-(.5+2*a/(q+r)))/a+b)
z=((8.8*(a+b)*2/c)-(.5+2a/(q+r)))/a+b)
z=((8.8*(a+b)*2/c)-(.5+2*a/(q+r)))/a+b)
z=((8.8*(a+b)2/c)-(.5+2*a/(q+r)))/a+b)
What will be the output of the following program? main() { int a=300,b,c; if (a>=400) b=300; c=200; printf("\n%d%d",b,c); }
300,200
error
garbage value,garbage value
garbage value,200
What will be the output of the C code given below?
main()
{
int a=500,b,c;
if(a>=400)
b=300;
c=200;
printf(“\n%d%d”,b,c);
}
error
300,200
garbage value,200
Pick the choice which represents the output of the given code. main() { int j; while(j<=10) { printf("\n%d",j); j=j+1; } }
Generates error
Output cannot be predicted
11
1
choose the right answer for the following code. main() { int i=1; while(i<=10); { printf("\n%d",i); i++; } }
1
2
No output
1,2,3,4,5,6,7,8,9,10
Guess the output of the program given below .
main()
{
char x;
while(x=o;x<255;x++)
printf(“\nAscil value %d character%c”,x,x);
}
The ASCII value of x is printed 255 times
it indicates an error
Indefinite output
It indicates error since the same variable x cannot be initialized to 0 and x.
each subscript in an array is________
float
integer
any data type
0
How many elements does the array int a[5] contain?
5
6
4
7
Which one of the following declares a one dimensional 30 element character array?
char name[31]
char name[30]
char name[29]
char name[]
Which of the following is not a correct variable type?
int
real
char
double
Write the C statement for the following C statement “a function called add accepts two integer arguments and returns a floating point value”
float add (int,int)
float add (int a, int b)
float add ()
Choose the meaning of the following statement given in C int(*pf)(char*a,char*b)
pf is a function that accepts two characters as arguments and return and integer.
pf is a function that accepts two characters as arguments and return and integer.
pf is a pointer to a function that accepts two pointers to characters as arguments and returns an integer.
pf is a pointer to a function that accepts two characters as arguments and returns an integer.
& is a/an__________
Binary operator.
Unary operator.
Conditional operator.
Assignmen operator.
The getchar () function reads a__________
String from a file
Character from a file
String from the keyboard
Character from the keyboard
What is a preprocessor directive?
It is a message from compiler to the programmer.
It is a message from compiler to the linker.
It is a message from programmer to preprocessor.
It is a message from programmer to microprocessor.
Which of the following holds (s) and advantage of using macros over functions?
functions must have parameters; macros do no.
The program is executed faster when a macro is used.
Values passed to functions must be of a specific data type; values passed to macros do not.
when macros are used many times in a program they are expanded each time.
The C preprocessor is a collection of statements,called__________
Directive
Symbolic
Include
None
Which of the statements is false with respect to structure and functions?
The general format of sending a copy of a structure to the called function is function name(structure variable name)
The called function must be declared for its type, appropriate to the data types it is expected to return.
The structure variable used as the actual argument and the corresponding formal argument in the called function must be of the same struct type.
when a function returns a structure, it is not necessary that it must be assigned to a structure of identical type in the calling function.
The major distinction between the structure and unions is in terms of ________
Storage
Declaration of members
Accessing the members
Syntax
Usage.
The maximum length of a variable in C is__________
8
16
32
64
The variable name can be started with__________
Underscore symbol(_)
Asterisk symbol(*)
Ampere sand symbol(&)
Numerals and characters.
What is the result of 16>>2?
4.
8.
2.
5.
A break statement is control structures is used__________
To break the control from a switch statement
To break the loop
to continue a loop
None
Goto statement is__________
Preferable for transferring the control to another part of the program.
Preferable since it is easy to use
Avoid as it can cause unpreferable transfer of control block within the program
To continue with the next test condition of the loop
Continue statement is control structures is used i
For transferromg the control to another block of the program
To exit out of the present loop
To continue statement ends the current iteration of a loop
None
All the elements in the array must be__________
Initialized.
Defined.
Numeric.
None
If you declare an array without stating the elements, it will be set to________
A null value
Zero
A garbage value
None
Array are passed as arguments to a function by___________
Value
Reference
Using pointers
Both value and reference
Which one of the statements is not valid
The stract() function is used to concatenate the two string.
The strcmp() function is used to compare the two string.
strcpy() function determines the length of the string
All correct
Which of the following function(s) return(s) a value?
voidf()
voidf(int a, int b)
f()
float f(int a)
In the normal function call there will be________ arguments(s) for each formal argument
one actual
Two actual
One formal
Three
How many values are returned by a function?
Function does not return any values.
One
Two
Three
A C program contains the following statements.
int j, j=20; int *pi, *pj=&j;
pj=j+5; i=pj+5;pi=pj; *pi=i+j;
The value assigned to I is______
20
30
35
15
Suppose that x is a two dimensional integer array having 10 rows and 20 columns. The item in row 2 and column 5 can be accessed by:
x[2][5]
*((x+2)+5)
*x+2,**x=5
None
'&' symbol
Only (i) of the above
Only (ii) of the above
Only (iii) of the above
None
"%d" specifies
Integer value to be read or printed
Character values to be read or printed
Double values to be read or printed
String values to be read or printed
Scan function is used to __________
Reading values from the keyboard
Initializing variables
Printing the values to the console
Accepting a string
Which of the following is/are valid?
A union may be member of a structure
Structure and union may be freely mixed with arrays
Union may be used in all place where structure is allowed.
None
To create variables of large size in C program, the following are used ________
Structure
Union
Array
Structure, unions and arrays
Structure, unions.
Which of the following statements is valid with respect to the bit field?
Bit fields allow the packing of data in a structure.
Bit fields can be of any data type, including float and double.
Bit fields can have a size greater than the size of their base type.
Bit fields can be accessed using pointers to their address.
Which of the following is a valid way to declare a constant in C?
const int x = 10;
define x 10
int const x = 10;
Both (a) and (c)
What will be the output of the following code? main() { int a = 5; int b = 10; printf("%d", a + b); }
5,10
15
510
Error
Which of the following is not a valid loop structure in C?
repeat-until
for
do-while
while
Which of the following is a header file in C?
stdio.c
conio.h
main.h
program.c
The header file stdio.h mainly deals with:
String manipulation
Standard input/output
Mathematical functions
File handling only
Which header file is required for mathematical functions like sqrt()?
math.h
stdio.h
string.h
conio.h
Which of the following is a valid variable name in C?
1number
_value
float
long-int
Which statement is true about identifiers?
Identifiers can start with a number.
Identifiers can contain spaces.
Identifiers are case-sensitive.
Keywords can be used as identifiers.
Which of the following is an invalid variable declaration?
int age;
float marks;
char name[20];
double 2value;
Which function is used for formatted output in C?
printf()
scanf()
gets()
puts()
What is the correct format specifier for a float in printf()?
%d
%f
%c
%s
Which function is used for reading a single character from user?
scanf()
getchar()
gets()
putchar()
The ASCII value of character 'A' is:
65
97
66
64
Which of the following ASCII values corresponds to a newline character \n?
9
10
13
32
The ASCII value of digit '0' is:
48
49
65
97
Which of the following is not a valid C data type?
int
float
real
double
Which function is used to read a string from the user?
scanf()
printf()
gets()
putchar()
Which operator is used to access the value at an address in C?
&
*
->
%
What is the size of int data type in most 64-bit compilers?
2 bytes
4 bytes
8 bytes
Depends on compiler
What is the default return type of the main() function in C (modern compilers)?
int
void
float
char
Which escape sequence represents a tab space?
\t
\n
\r
\b
The ASCII value of lowercase 'a' is:
65
97
66
98
Which symbol is used to denote a preprocessor directive in C?
&
$
#
@
The C language was developed by:
Bjarne Stroustrup
Dennis Ritchie
James Gosling
Guido van Rossum
Size of double in C (on most systems) is:
1 byte
2 bytes
4 bytes
8 bytes
Which format specifier is used for a float with printf?
%d
%f
%c
%lf
++i is known as:
Post-increment
Pre-increment
Compound
Decrement
What is the value of 10 > 5 && 5 < 2?
1
0
True
Error
Correct syntax of a switch?
switch variable {case 1: … }
switch(variable) { case 1: … }
switch variable case1: …
switch-case(variable) …
For loop syntax is:
for(init; condition; update)
for(condition; init; update)
for(init; update; condition)
for(update; condition; init)
Which keyword skips current iteration?
stop
skip
continue
next
What is the output?
#include
What is the output?
#include
The C language was first developed in the year
1969
1972
1980
199
The C-preprocessors are specified with _________ symbol.
#
$
" "
&
Which is a valid relational operator?
<>
!=
=
:=
Which loop executes at least once?
for
do…while
while
nested for
Initialization, condition, and increment are used in
while
for
do…while
switch
What is printed by for(i=0;i<3;i++) printf("%d",i);?
0 1
0 1 2
1 2 3
1 2
Value of x? int x = 5; x *= 5;
10
15
25
7
Output?
#include
Output?
#include
Output?
#include
Output?
#include
Output?
#include
Correct syntax to print “Hello”?
printf(Hello);
printf("Hello");
print("Hello");
cout<<"Hello";
Correct ternary operator syntax?
condition ? expr1 : expr2
condition : expr1 ? expr2
?condition:expr1:expr2
if?expr1:expr2
Correct while loop syntax?
while (condition) { … }
while condition { … }
while: condition { … }
do while(condition);
Correct do–while syntax?
do { … } while(condition);
do while(condition) { … }
do(condition) { … };
whiledo { … };
Choose the valid compound assignment statement:
x =+ y;
x += y;
x = y+;
x + y =;
Which correctly checks if a is NOT equal to b?
if(a =! b)
if(a != b)
if(a <> b)
if(a =/= b)
Proper way to use else-if ladder:
if(cond1) … else if(cond2) … else …
if(cond1) … elseif(cond2) … else …
if(cond1) … else(cond2) …
if(cond1, cond2) … else …
Correct syntax for a for loop counting down from 10 to 1:
for(i=10;i>=1;i--) { … }
for(i=10;i>=1;i++) { … }
for i=10 to 1 { … }
for(i=10;i<=1;i--) { … }
