You are on page 1of 4

CSE101 ( Computer Programming) AT #3 (Quiz) SET A

Q1.What is the output of this C code?


Q7. Which of the following function is more appropriate for reading
#include <stdio.h> in a multi-word string?
void main()
{ a) printf(); c) scanf();
int a[2][3] = {1, 2, 3, 4, 5}; b) gets(); d) puts();
int i = 0, j = 0; Ans: b
for (i = 0; i < 2; i++) Q8. What will be output when you will execute following C
for (j = 0; j < 3; j++)
code?
printf("%d", a[i][j]);
}
#include<stdio.h>
void main(){
a) 1 2 3 4 5 0 c) 1 2 3 4 5 5
int arr[][3]={{1,2},{3,4,5},{5}};
b) 1 2 3 4 5 junk d) Run time error
printf("%d %d %d",sizeof(arr),arr[0][2],arr[1][2]);
}
Ans: a
a) 12 3 5 c) 12 0 5
Q2. What is the right way to initialize an array? b) 18 0 5 d) 18 3 5

a) int num[6]={2,4,6,8,10,12}; Ans: b


b) int num{}={2,4,6,8,10,12};
c) int num{6}={2,4,6,8,10,12}; Q9. If the two strings are identical, then strcmp() function returns
d) int num(6)={2,4,6,8,10,12};
a) -1 b) 1
Ans: a c) 0 d) Yes
Ans: c
Q3. What will be the output of the program?
#include<stdio.h> Q10. How will you print \n on the screen?
void main( )
{ a) printf("\n"); b) echo "\\n";
int a[5]={5,1,15,20,25}; c) printf('\n'); d) printf("\\n");
int i,j,m;
i=++a[1]; Ans: d
j=a[1]++;
m=a[i++]; Q11. The ____ operator is used to extract the address for a variable.
printf("%d, %d, %d", i,j,m);
} a) pointer (^)
b) address (&)
c) indirection (*)
a) 2, 3, 20 c) 2, 1, 15
d) selection (>)
b) 3, 2, 15 d) 1, 2, 5

Ans: b Ans: b
Q12. Which of the following statements declares a function
Q4. What will be the output of the program if the array begins at with a pointer variable as a parameter?
65472 and each integer occupies 2 bytes?
void main( ) a) void fun (int ptr);
{ b) void fun (int& ptr);
int a[3][4]={1,2,3,4,4,3,2,1,7,8,9,0}; c) void fun (*int ptr);
printf("%u %u", a+1, &a+1); d) void fun (int* ptr);
} Ans: d
a) 65474, 65488 c) 65480, 65496 Q13. Array passed as an argument to a function is interpreted as:
b) 65480, 65488 d) 65474, 65476
Ans: c a) Sizeof the array
b) Values of the first elements of the array
Q5. What is the index number of the last element of an array with 29 c) Address of the first element of the array
elements? d) Number of the elements in the array
a) 29 c) 27
b) 28 d) Programmer-defined Ans: c
Ans: b Q14. Which of the following statements about pointer constants is
true?
Q6. Which of the following gives the memory address of the first a) The value in a pointer constant can change from run to run.
element in array foo, an array with 100 elements? b) The type of a pointer constant is address.
a) foo[0]; c) &foo; c) The asterisk operator (*) extracts the address for a variable.
b) foo[1]; d) foo; d) Pointer constants cannot be saved.
Ans: a
Ans: c
Q15. Which of the following statements about two-dimensional arrays b) 30 d) Compilation Error
is false?
Ans: c
a) The size of the first dimension is optional.
b) Two-dimensional arrays must be unitialized or fully initialized.
Q20. Which of the operations are valid on pointers?
c) By convention the first dimension specifies the number of rows.
d) Accessing individual values requires two indexes.
a) Comparison c) Addition of two pointers
b) Division d) Modulus
Ans: b
Ans: a
Q16. Which of the following storage classes have a local scope?

a) static Q21. Have a look at the following piece of code and state the output.
b) extern
c) function void main()
d) array {
char str[20]="AB\0CDE";
Ans: a int i;
Q17. Have a look at the following piece of code and state the output.
for(i=0;str[i]!='E'&&str[i]!='\0';i++)
printf("%c",str[i]);
int a; getch();
int main() }
{ a) Prints ABCD on the screen.
int *ptr=&a; b) Prints ABCDE on the screen.
printf("\n%d",*&*(ptr)); c) Prints AB on the screen.
getch(); d) Results in a compiler error.
} Ans: c
a) Prints a garbage value on the screen.
Q22. Let x be an array, which of the following statements are
b) Prints 0 on the screen.
illegal:
c) Prints the address of variable a on the screen.
I. ++x
d) Results in a compiler error.
II. x+1
III. x++
Ans: b IV. x*2

Q18. Have a look at the following piece of code and state the output. a) I and II c) II and III
b) I, II and III d) I, III and IV
void fun(double *);
void main() Ans: d
{
double f=24.44,*ptr=&f; Q23. Which of the following storage class variables automatically
fun(ptr); get initialized to 0.
printf("\n%f",*ptr); a) static c) register
getch(); b) auto d) array
}
void fun(double *ptr) Ans: a
{
++ptr; Q24. Have a look at the following piece of code and state the
} output.

a) Prints 24.44 on the screen void main()


b) Prints a garbage value on the screen {
c) Prints an address on the screen register int a;
d) Results in a compiler error. printf("\n%d",a);
getch();
Ans: a }
Q19.What will be the output of following code? a) Prints 0 on the screen.
#include<stdio.h> b) Prints a random number on the screen.
c) Prints an address on the screen.
#include<conio.h>
d) Results in a compiler error.
void fun(int *p)
{
int q = 10; Ans: b
p = &q;
} Q25. The function which can be used to change the case of a string is
a) strcase
void main()
b) strcmp
{ c) strrev
int r = 20; d) strlwr
int *p = &r;
fun(p); Ans: d
printf("%d", *p);
getch();
}
a) 10 c) 20
CSE101 ( Computer Programming) AT #3 (Quiz) SET B
Q1. Which of the following statements about two-dimensional arrays
is false?
a) 10 b) 20
e) The size of the first dimension is optional. c) 30 d) Compilation Error
f) By convention the first dimension specifies the number of rows.
g) Two-dimensional arrays must be unitialized or fully initialized. Ans: b
h) Accessing individual values requires two indexes.
Q6. Which of the operations are valid on pointers?
Ans: c
Q2. Which of the following storage classes have a local scope? c) Modulus b) Addition of two pointers
c) Division d) Comparison
e) array
f) extern
g) function Ans: d
h) static
Q7. Have a look at the following piece of code and state the output.
Ans: d
void main()
Q3. Have a look at the following piece of code and state the output. {
int a; char str[20]="AB\0CDE";
int main() int i;
{ for(i=0;str[i]!='E'&&str[i]!='\0';i++)
int *ptr=&a; printf("%c",str[i]);
printf("\n%d",*&*(ptr)); getch();
getch(); }
} a) Prints AB on the screen.
b) Prints ABCDE on the screen.
e) Prints a 0 on the screen c) Prints ABCD on the screen.
f) Prints garbage value on the screen d) Results in a compiler error.
g) Prints the address of variable a on the screen
h) Results in a compiler error
Ans: a
Ans: a
Q8. Let x be an array, which of the following statements are
Q4. Have a look at the following piece of code and state the output. illegal:
I. ++x
void fun(double *); II. x+1
void main() III. x++
{ IV. x*2
double f=24.44,*ptr=&f;
a) I and II b) I, III and IV
fun(ptr); c) I, II and III d) II and III
printf("\n%f",*ptr);
getch(); Ans: b
}
void fun(double *ptr) Q9. Which of the following storage class variables automatically
{ get initialized to 0.
++ptr;
} a) auto b) register
c) static d) array
e) Prints a garbage value on the screen
f) Prints an address on the screen Ans: c
g) Results in a compiler error.
h) Prints 24.44 on the screen Q10. Have a look at the following piece of code and state the
Ans: d output.

Q5.What will be the output of following code? void main()


{
#include<stdio.h> register int a;
#include<conio.h> printf("\n%d",a);
void fun(int *p) getch();
{ }
int q = 10;
p = &q; a) Prints 0 on the screen.
} b) Results in a compiler error.
void main() c) Prints an address on the screen.
d) Prints a random number on the screen.
{
int r = 20;
int *p = &r; Ans: d
fun(p);
printf("%d", *p);
getch();
}
Q11.What is the output of this C code? a) printf(); b) scanf();
c) gets(); d) puts();
#include <stdio.h>
Ans: c
void main()
{ Q18. What will be output when you will execute following C
int a[2][3] = {1, 2, 3, 4, 5}; code?
int i = 0, j = 0;
for (i = 0; i < 2; i++) #include<stdio.h>
for (j = 0; j < 3; j++) void main(){
printf("%d", a[i][j]); int arr[][3]={{1,2},{3,4,5},{5}};
} printf("%d %d %d",sizeof(arr),arr[0][2],arr[1][2]);
}
a) 1 2 3 4 5 5 b) 1 2 3 4 5 0
c) 1 2 3 4 5 junk d) Run time error c) 12 3 5 b) 12 0 5
c) 18 0 5 d) 18 3 5
Ans: b
Ans: c
Q12. What is the right way to initialize an array?
Q19. If the two strings are identical, then strcmp() function returns
e) int num[6]={2,4,6,8,10,12};
f) int num{}={2,4,6,8,10,12}; a) -1 b) 1
g) int num{6}={2,4,6,8,10,12}; c) 0 d) Yes
h) int num(6)={2,4,6,8,10,12};
Ans: c
Ans: a Q20. How will you print \n on the screen?

Q13. What will be the output of the program? a) printf("\n"); b) echo "\\n";
#include<stdio.h> c) printf('\n'); d) printf("\\n");
void main( )
{ Ans: d
int a[5]={5,1,15,20,25};
Q21. The ____ operator is used to extract the address for a variable.
int i,j,m;
i=++a[1]; a) address (&)
j=a[1]++; b) pointer (^)
m=a[i++]; c) indirection (*)
printf("%d, %d, %d", i,j,m); d) selection (>)
}
Ans: a
a) 2, 3, 20 b) 2, 1, 15
Q22. Which of the following statements declares a function
with a pointer variable as a parameter?
c) 3, 2, 15 d) 1, 2, 5
a) void fun (int * ptr);
Ans: c b) void fun (int& ptr);
c) void fun (*int ptr);
Q14. What will be the output of the program if the array begins at d) void fun (int ptr);
65472 and each integer occupies 2 bytes?
void main( ) Ans: a
{
int a[3][4]={1,2,3,4,4,3,2,1,7,8,9,0}; Q23. Array passed as an argument to a function is interpreted as:
printf("%u %u", a+1, &a+1);
a) Sizeof the array
}
b) Address of the first element of the array
c) 65474, 65488 b) 65480, 65496
c) Value of the first element of the array
c) 65480, 65488 d) 65474, 65476
d) Number of the elements in the array
Ans: b Ans: b
Q15. What is the index number of the last element of an array with 27 Q24. Which of the following statements about pointer constants is
elements? true?
a) 27 b) 28 a) The type of a pointer constant is address.
c) 26 d) Programmer-defined b) The asterisk operator (*) extracts the address for a variable.
c) The value in a pointer constant can change from run to run.
Ans: c d) Pointer constants cannot be saved.

Q16. Which of the following gives the memory address of the first Ans:c
element in array foo, an array with 100 elements?
a) foo[0]; b) &foo; Q25. The function which can be used to change the case of a string is
c) foo[1]; d) foo;
a) strcase
b) strlwr
Ans: b c) strrev
d) strcmp
Q17. Which of the following function is more appropriate for reading
in a multi-word string? Ans: b

You might also like