WorksheetsTest 1 - 23CS1005 Programming for Problem Solving
Total questions: 50
Worksheet time: 36mins
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
}
hi
hello
no
error
The switch statement takes a given integer value then seeks a matching value among a number of _______ statements.
break
case
switch
goto
How many loops are there in C
1
3
2
4
which is the only function all C programs must contain?
start()
sys()
main()
scanf()
Which of the following is not a correct variable type?
float
real
int
double
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1, b = 1, c;
c = a++ + b;
printf("%d, %d", a, b);
}
a=1, b=1
a=2, b=1
a=1, b=2
a=2, b=2
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0;
int j = i++ + i;
printf("%d\n", j);
}
0
1
2
compile time error
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1, b = 1;
switch (a)
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
}
yes
no
yes no
compile time error
Library function pow() belongs to which header file?
math.h
square.h
stdio.h
conio.h
Is it possible to run program without main() function?
yes
no
may be
How many main() function we can have in our project?
1
2
no limit
depends on the program
int x = 10;
int main()
{
int x = 0;
printf("%d",x);
return 0;
}
10
0
compile error
undefined
What should be the output:
int main()
{
int a = 10/3;
printf("%d",a);
return 0;
}
3.33
3.0
3
0
C programs are converted into machine language with the help of
An Editor
A compiler
An operating system
None of these.
Which one of the following is not a valid identifier?
_examveda
1examveda
exam_veda
examveda1
Which is the only function all C programs must contain?
start()
system()
printf()
main()
int main ()
{
int x = 24, y = 39, z = 45;
z = x + y;
y = z - y;
x = z - y;
printf ("%d %d %d", x, y, z);
}
24 39 63
39 24 63
24 39 45
39 24 45
A name having a few letters, numbers and special character _(underscore) is called
keywords
reserved keywords
tokens
identifiers
Which of the following is not a valid variable name declaration?
int a3;
int 3a;
int _A3;
int a_3
All keywords in C are in ____________
Lowercase
Uppercase
Camelcase
None of these
A translator which reads an entire program written in a high level language and converts it into machine language code is:
Assembler
Compiler
Linker
Loader
Diamond shaped symbol is used in flowcharts to show the-
decision box
statement box
error box
if-statement box
Which is correct with respect to size of the data types?
char > int > float
int > char > float
char < int < double
double > char > int
Which is valid C variable declarations?
int my_num = 100,000;
int my_num = 100000;
int my num = 1000;
int $my_num = 10000;
The functions printf() and scanf() are defined in which of the following library file:-
math.h
conio.h
stdio.h
stdlib.h
Which is variable declaration?
int a,b;
c=a+b;
printf("%d%d",a,b)
scanf("%d%d",&a,&b);
how to print a and b variable of int and float respectively
scanf("%d%f",&a,&b);
printf("%d%f",a,b);
printf("%f%d",&a,&b);
printf("%f%d",&a,&b);
What will be the output of the C code?
Hello World! x;
Hello World! followed by a junk value
Compile time error
Hello World!
The format identifier ‘%i’ is also used for _____ data type.
char
int
float
double
What will be the output of the following C code?
3 2 3
2 2 3
3 2 2
2 3 3
Find the output in following code
int main ()
{
int a,b ;
a= b= 4 ;
b =a++;
Printf ( " %d %d %d %d", a++, --b, ++a, b--);
}
5 3 73
5 4 5 3
6 2 6 4
Syntax Error
Find error/output in following code
int main ()
{
int m = -10,n =20;
n = ( m < 0) ? 0 : 1;
printf ( " %d %d ", m,n ) ;
}
-10 0
10 20
20 -10
0 1
Find error/ output in following code
int main ()
{
int i = 0;
for ( ; ;)
printf ( "%d", i) ;
return 0;
}
O times
Infinite times
10 times
1 times
Find Error/ output in following code
int main ()
{
int x = 1;
While (x= 0)
printf (" Hello");
}
Hello
No output
Infinite time Hello display
Error in code
Find Error/ output in following code
Void main ()
{
printf ( " % d " , printf ( " computer science"));
}
Computer science16
16computer science
Computer science
Computer science18
Point out the error in the program
f ( int a, int b)
{
int a;
a = 20;
return a;
}
Missing parentheses in return statement
The function should be defined as int f ( int a, int b)
Redeclaration of a
None of the above
What will be the output of following program?
Hello
OK
Hello
OK
Error
What will be the output of the program?
This is default
This is case 1
This is case 3
This is default
This is case 1
This is case 3
This is default
What will be the output of following program ?
Hello
ERROR
No Output
Garbage Value
The keyword break cannot be simply used within
while statements
for statement
if else
do while
switch statement accept
int
char
long
all
Which of the following correctly shows the hierarchy of arithmetic operations in C?
/ + * -
* - / +
+ - / *
/ * + -
Which of the following is not logical operator?
&
&&
||
!
When does the code block following while(x<100) execute?
When x is less than one hundred
When x is greater than one hundred
When x is equal to one hundred
while it wishes
Input/output function prototypes and macros are defined in which header file?
conio.h
stdlib.h
stdio.h
dos.h
Which of the following is the correct operator to compare two variables?
equal
=
:=
==
What is the only function all C programs must contain?
start()
system()
main()
Program()
The "\n" character does which of the following operations?
Double line spacing
Character deletion
Character backspace
Places cursor on the next line
Which arithmetic operator in C returns the integer remainder of the result of dividing its first operand by its second?
%
/
\
*
