Font size
WorksheetsPROGRAMMING IN C CO-1,2
Total questions: 50
Worksheet time: 50mins
1.
What is the range of values that can be stored by int datatype in C?
-(2^31)to(2^31)-1
-256 to 255
-(2^63)to(2^63)-1
0 to(2^31)-1
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int a = 3, b = 5;
int t = a;
a = b;
b = t;
printf("%d %d", a, b);
return 0;
}3 5
3 3
5 5
5 3
Final step of the for loop is ----------------------------
Incrementing
decrementing
Both
Incrementing / decrementing
What is the sizeof(char) in a 32-bit C compiler?
1 bit
2 bits
1 Byte
2 Bytes
Which is valid C expression?
int my_num = 100000;
int my_num = 100,000;
int my num = 1000;
int $my_num = 10000;
scanf() is a predefined function in______header file.
stdarg. h
iostream.h
conio.h
stdio.h
Which of the following is not a high level programming language?
Assembly
C++
Java
Python
Conditional operators are used for decision making in C.
int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;
printf("%d",z);
12
16
20
0
The output of an arithmetic expression with integer and float is __________.
int
float
can't be defined
operation not possible
#include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}
24
3
23
4
!= is the example of ____________________ operator.
Relational
Logical
Assignment
Conditional
What is the value of EOF?
-1
1
0
10
What will be the value of x in the following code snippet?
#include <stdio.h>
void solve() {
int x = printf("Hello");
printf(" %d", x);
}
int main() {
solve();
return 0;
}10
5
1
0
Which of the following is the proper syntax for declaring macros in C?
#define long long II
#define II long long
#define II
#define long long
What is the output of the following code snippet?
int main() {
int sum = 2 + 4 / 2 + 6 * 2;
printf("%d", sum);
return 0;
}2
15
16
18
How do you initialize an array in C?
int arr[3] = (1,2,3);
int arr(3) = {1,2,3};
int arr[3] = {1,2,3}
int arr(3) = (1,2,3)
#include <stdio.h>
#define ERRMSG(a) printf("Error=%d",a);
int main()
{
ERRMSG(10);
return 0;
}
Error=10
error
no output
What are the types of C Preprocessor Directives.?
Macros
Conditional Compilation
File Inclusion
All the above
#include <stdio.h>
#define message_for(a, b) \
printf(#a " and " #b ": are alphabets!\n")
int main(void) {
message_for(C,D);
return 0; }
error
C and D are alphabets
C "and" D are alphabets
Compilation error
macro25 = 47
macro47 = 25
Runtime error
#include <stdio.h>
#define MAX(x,y) ((x) > (y) ? (x) : (y))
int main(void) {
printf("Max between 20 and 10 is %d\n", MAX(10, 20));
return 0; }
10
error
20
Max between 20 and 10 is 20
++ and -- are unary operators.
True
False
What is the output ?
int var;
var = !(0 && (2||1));
printf("%d",var);
0
2
1
Compiler Error
what is the ouput of the below program?
int main()
{
int i=10, j=20;
if((i=100) && (j==20))
{
printf("Have a nice day");
}
else
{
printf("condition not true");
}
return 0;
}
No output
Have a nice day
condition not true
Complier Error
Char 65
Integer 65
Bye
Compilation Error
GREEN
RABBIT
GREEN
RABBIT is printed unlimited number of times.
None of the above
What does the following code fragment write to the monitor?
Under
Over
Under the limit
Over the limit
For loop in a C program, if the condition is missing?
it is assumed to be present and taken to be false
it is assumed to be present and taken to the true
it result in a syntax error
execution will be terminated abruptly
What is the output of C Program.?
int main()
{
int a=32;
do
{
printf("%d ", a);
a++;
if(a > 35)
break;
}
while(1);
return 0;
}
No Output
32 33 34
32 33 34 35
Compiler error
What is the output of this C code?
Compile time error
Hi Hi
Hi
Varies
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
(a)
How to initialize an array in C? tick all the correct statement.
int arr[3] = {1,2,3}
int arr(3) = {1,2,3};
int arr(3) = (1,2,3);
int arr[3] = (1,2,3);
int arr[3] = {0}
How can I store the value 10 into the first row, third column of my array that I have declared as int numbers[10][10]?
int numbers[1][2] = 10;
numbers[0][2] = 10;
numbers[2][3] = 10;
numbers[1][3] = 10
0
1
5
garbage value
Error
Arrays are structures that hold multiple variables of the _____________ data type
int data type
char data type
same data type
different data type
he following program
main( )
{
static int a[ ] = { 7, 8, 9 } ;
printf( "%d", 2[ a ] + a[ 2 ] ) ;
}
results in bus error
results in segmentation voilation error
will not compile successfully
none of these
Given the code, what is in values[2][1] ?
7.9
9.2
7.3
0.5
Predict output of following program
int main(){
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
1 1 1 1 1
1 followed by 4 junk values
1 0 0 0 0
Compiler error
What is the proper declaration for an array that has 2 rows and 3 columns?
type arr[2][2];
arr[2][3] type;
type arr[2][3];
type arr[4][3];
Pick all correct statements.
int A[][]={1,2,3,4};
int A[2][]={1,2,3,4};
int A[][2]={1,2,3,4};
int A[2][2]={1,2,3,4};
How can I store the value 10 into the second row, first column of my array that I have declared as int numbers[10][10]?
int numbers[1][2] = 10;
numbers[1][2] = 10;
numbers[2][3] = 10;
numbers[1][0] = 10
What is the output of
#include <stdio.h>
int main()
{
char str[8]="IncludeHelp";
printf("%s",str);
return 0;
}
IncludeHelp
IncludeH
Error
No Output
Array can be considered as set of elements stored in consecutive memory locations but having __________.
Same data type
Different data type
Same scope
None of these
What is the output of C program with strings.?
int main()
{
char str1[]="SMART";
char str2[10];
str2 = str1;
printf("%s",str2);
return 0;
}
SMART
SMART followed by 5 spaces
SMART followed by 4 spaces
can not assign one string to another
int main()
{
char str[25];
scanf("%s", str);
printf("%s",str);
return 0;
}
//input: South Africa
South
South Africa
S
Compiler error
Which of the following function is more appropriate for reading in a multi-word string?
scanf()
printf()
puts()
gets()
String is an array of characters with …….. character as the last element of array.
Null
Empty
0
1
