Font size
WorksheetsC programming Basics
Total questions: 40
Worksheet time: 20mins
Which of the following is a valid variable name in C?
int 2x
int _x
float double
char @num
What is the correct format specifier for integer output?
%i
%d
%c
%f
Which header file is required for printf() and scanf()?
(a)
Every C program must have which function?
main()
start()
execute()
program()
What is the correct way to comment a single line?
/* comment */
// comment
# comment
-- comment
The smallest individual unit in a program is called:
Variable
Function
Token
Operator
What is the correct way to end a statement in C?
.
;
:
,
Which of these is not a keyword in C?
auto
main
static
default
The C language was developed by:
Dennis Ritchie
Charles Babbage
James Gosling
Guido van Rossum
Which of the following is not a data type in C?
int
float
real
char
The operator == is used for:
Assignment
Comparison
Bitwise AND
None
What is the output of printf("%d", 5/2);?
2.5
2
2.0
Error
Which operator has the highest precedence?
+
*
=
&&
The remainder operator in C is:
/
%
mod
//
Which of these is a logical operator?
&&
==
+
%
What will be the output of this code? int x=0; if(x) printf("Hi"); else printf("Hello");
Hi
Hello
Error
No output
The switch statement can work with which type?
int
float
double
all
The keyword used to exit a loop immediately is:
stop
exit
break
return
What is the output of this code? for(int i=0;i<3;i++); printf("%d",i);
012
3
2
Error
The loop that executes at least once is:
for
while
do-while
nested for
Correct declaration of an array:
int arr[5];
int arr;[5]
int arr[]5;
arr int[5];
The last index of an array of size 10 is:
10
9
11
Undefined
Which function finds the length of a string?
strlen()
strsize()
size()
len()
What is the null character in C strings?
' '
' '
' '
'0'
Which header is required for string functions?
Correct function declaration:
function add(int a,int b);
int add(int a,int b);
declare add(int,int);
void add a,b;
Which keyword is used to return a value from a function?
return
break
goto
exit
What is the default return type of a function in C (if not specified)?
float
void
int
double
A function that calls itself is called:
inline function
recursion
nested
reentrant
The value passed to a function is called:
argument
variable
pointer
macro
A pointer stores:
a value
an address
both
none
Which operator gives the address of a variable?
*
&
->
%
Which function dynamically allocates memory?
alloc()
malloc()
new()
calloc()
If int *p; and int a=10; p=&a;, what does *p give?
address of a
10
garbage
error
Which function releases dynamically allocated memory?
remove()
delete()
free()
release()
Output of:
int a=5;
printf("%d %d", a++, ++a);
5 7
6 7
Undefined
5 6
What will happen if you print an uninitialized variable?
Prints 0
Prints garbage
Error
Stops execution
Which keyword is used to define constants?
constant
final
#define
const
What will be the output of this code? int x=1; do { printf("%d ", x); x++; } while(x<1);
1
No output
Infinite
Error
What is the output of the following code? printf("%d", sizeof('A'));
1
2
4
Depends on system
