WorksheetsCP midsem2 set 1
Total questions: 31
Worksheet time: 32mins
(mandatory) Enter your details carefully :
Enter your 11 digit enrollment number:
Enter your class (DC1/DC2/DC3):
Enter your full name in following format (firstname lastname) ex. Pooja Raval
Which of the following is the correct way to declare a function in C?
int functionName
b) functionName int()
c) int functionName()
d) functionName() int
And
What will be the output of the following program?
#include<stdio.h> int main() {
int i; int j = 2;
for(i=1; i<=j; i++){
printf("%d", ++i); }
return 0; }
1
3
2
0
Predict the output:
#include <stdio.h>
struct Point {
int x,y; };
int main() {
struct Point p;
p.x = 5;
p.y = 10;
printf("(%d, %d)", p.x, p.y);
return 0; }
Predict the output:
#include <stdio.h>
int main() {
int x = 5;
int *ptr = &x;
printf("%p", ptr);
return 0;}
What is the return type of the fopen() function in C?
int
char
FILE *
void
Which mode is used to open a file for reading in C?
"r"
"w"
"a"
"rb"
Which function is used to read data from a file in C?
fread()
fwrite()
fscanf()
fprintf()
Which function is used to write data to a file in C?
fread()
fwrite()
fscanf()
fprintf()
Which mode is used to open a file for both reading and writing in C?
"r+"
"w+"
"a+"
"rw"
Predict the output:
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr + 2;
printf("%d", *ptr);
return 0;}
1
2
3
Compiler error
Which of the following correctly declares a pointer to an array in C?
int ptr[];
ptr int[];
int *ptr[];
int (*ptr)[];
Which of the following is not a valid function declaration in C?
int sum(int a, int b);
void multiply(float x, float y);
average(int[], int);
float product(float, float);
Which of the following is true about function parameters in C?
Parameters are optional
Parameters cannot have default values
Parameters are variables used to pass values to a function
Parameters can only be of type int
