NEW
Font size
WorksheetsQuiz on c program
Total questions: 50
Worksheet time: 50mins
What is a correct syntax to output "Hello World" in C
Console.WriteLine(“Hello World”);
System.out.println(“Hello World”);
cout<<”Hello World”;
printf(“Hello World”);
How do you insert COMMENTS in C code?
— This is a comment
# This is a comment
// This is a comment
* This is a comment
When a variable is created in C, a memory address is assigned to the variable.
True
False
In C, code statements must end with a semicolon (;)
True
False
How can you create a variable with the numeric value 5?
val num = 5;
num = 5;
num = 5 int;
int num = 5;
How can you create a variable with the floating number 2.8?
float num=2.8;
val num = 2.8;
num=2.8 float;
num=2.8 double;
Which operator is used to add together two values?
The & sign
The ADD keyword
The * sign
The + sign
Which function is often used to output and print values?
printword()
printf()
write()
output()
Which format specifier is often used to print integers?
%s
%c
%d
%f
Which operator can be used to compare two values?
==
=
<>
><
#include <stdio.h>
int main()
{
float q = ‘a’;
printf(“%f”, q);
return 0;
}
run time error
a
97.000000
a.0000000
Which of these is NOT a relational or logical operator?
=
||
==
!=
What is a short int in C programming?
The basic data type of C
Qualifier
Short is the qualifier and int is the basic data type
All of the mentioned
Predict the output of following C program
#include <stdio.h>
int main()
{
char a = 012;
printf("%d", a);
return 0;
}
Compiler Error
12
10
Empty
The format identifier ‘%i’ is also used for _____ data type.
char
int
float
double
A long integer is at least 32 bits wide and a short integer is at least 16 bits wide
True
False
Which operator can be used to find the memory size (in bytes) of a data type or variable?
length()
size()
sizeof()
length()
Which keyword can be used to make a variable unchangeable?
const
constant
readonly
final
Who is the father of C language?
Steve Jobs
James Gosling
Dennis Ritchie
Rasmus Lerdorf
Which of the following is not a valid C variable name?
int number;
float rate;
int variable_count;
int $main;
All keywords in C are in ____________
LowerCase letters
UpperCase letters
CamelCase letters
None of the mentioned
Which is valid C expression?
int my_num = 100,000;
int my_num = 100000;
int my num = 1000;
int $my_num = 10000;
Which of the following cannot be a variable name in C?
volatile
true
friend
export
Which keyword is used to prevent any changes in the variable within a C program?
immutable
mutable
const
volatile
The C-preprocessors are specified with _________ symbol.
#
$
" '
&
When was C programming developed?
The 1950s
The 1960s
The 1980s
The 1970s
What was C programming adapted from?
C++
Combined programming language
python
All of the above
#include <stdio.h>
int main()
{
int i;
i = 1, 2, 3;
printf("%d", i);
return 0;
}
output..........?
1
3
Garbage value
compile time error
What is the output of the below program?
#include <stdio.h>
int main() {
int i = 2;
switch (i) {
case 0:
printf("CSIT");
break;
case 1:
printf("CSD");
break;
default:
printf("CSE");
}
return 0;
}
CSIT
CSD
CSE
compile time error
#include <stdio.h>
int i;
int main() {
if (printf(“Hi”)) {
i=2;
} else {
printf("Else");
}
return 0;
}
What is the output of above program?
Else
Compilation error
Hi
Error: misplaced else
#include <stdio.h>
int main()
{
int a = 10, b = 20, c = 30;
if (c > b > a)
printf("TRUE");
else
printf("FALSE");
return 0;
}
TRUE
FALSE
Wrong
Compile time error
Which statement is used to make decisions in C?
loop
if
return
What will the following code output?
if (5 > 3) {
printf("True");
}
else {
printf("False");
}
True
False
Errror
None
What does the else statement do?
Executes if the condition is true
Executes if the condition is false
Always executes
None of the above
Which of the following is a valid syntax for a switch statement?
switch (expression) { case: }
switch { expression }
switch (expression) { case value: }
switch (case value) { expression }
What will be the output of this code?
int x = 10;
if (x < 5) {
printf("Low");
}
else {
printf("High");
}
Low
High
Error
None
In C, what does the ternary operator do?
Repeats a statement
Evaluates a condition and returns one of two values
Defines a function
None of the above
Which of the following is true about the switch statement?
It can evaluate conditions of different types
It can have multiple default cases
It can include break statements
It requires a boolean expression
What is the purpose of the break statement in a loop or switch?
To pause execution
To exit the loop or switch
To skip the current iteration
To repeat the statement
What happens if no case matches in a switch statement?
An error occurs
The program crashes
The default case is executed, if it exists
Nothing happens
Which of the following is not a conditional statement in C?
if
else
for
switch
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 10;
if (a == a--)
printf("TRUE 1\t");
a = 10;
if (a == --a)
printf("TRUE 2\t");
}
TRUE 1
TRUE 2
TRUE 1 TRUE 2
Compiler Dependent
What will be the final value of d in the following C code?
#include <stdio.h>
int main()
{
int a = 10, b = 5, c = 5;
int d;
d = b + c == a;
printf("%d", d);
}
Syntax error
1
5
10
Output of following program?
#include<stdio.h>
int main()
{
float x = 0.1;
if ( x == 0.1 )
printf("IF");
else if (x == 0.1f)
printf("ELSE IF");
else
printf("ELSE");
}
ELSE IF
IF
ELSE
compile error
What is the result of logical or relational expression in C?
True or False
0 or 1
0 if an expression is false and any positive number if an expression is true
None of the mentioned
What will be the final value of x in the following C code?
#include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}
3.75
Depends on compiler
3
24
Which operator is used for incrementing a variable by 1?
--
++
+=
=
What is an example of iteration in C?
for
while
do-while
all of the mentioned
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = -3;
int k = i % 2;
printf("%d\n", k);
}
Compile time error
-1
1
Implementation defined
What does the '&&' operator represent?
Logical OR
Bitwise AND
Logical AND
Bitwise OR
