Font size
WorksheetsPSC Quiz1
Total questions: 20
Worksheet time: 24mins
A function may have any number of return statements each returning different Values.Say True or False
True
False
which keyword is used to create new names for datatypes
(a)
By considering a 32 bit processor,Give the size of the following Structure
struct value
{
int num[35];
float f;
char c;
};
145
144
148
150
A Program under execution will be in which memory
Cache Memory
Secondary Memory
None
Main Memory
#include<stdio.h>
main()
{ int x = 5;
if(x=5)
{
if(x=5) break;
printf("Hello");
}
printf("Hi");
}
Hello
Hi
Compiler Error
Logical Error
All functions can be recursively called except the main function
True
False
#include<stdio.h>
main()
{
char s[20] = "Hello\0Hi";
printf("%d %d", strlen(s), sizeof(s));
}
5,9
9,20
5,20
5,5
Similarity between a structure, union and enumeration,
A - All are helpful in defining new variables
B - All are helpful in defining new data types
C - All are helpful in defining new pointers
D - All are helpful in defining new structures
What actually get pass when you pass an array as a function argument?
A - First value of elements in array
B - Base address of the array
C - All value of element in array
D - Address of the last element of array
What is the output of following program?
# include <stdio.h>
void fun(int x)
{
x = 30;
}
int main()
{
int y = 20;
fun(y);
printf("%d", y);
return 0;
}
30
compiler error
run time error
20
Code to change the 3rd array value to 50 using pointers
int main()
{
int a[] = {10,20,30};
int *p = a;
----------------------;
}
p+3 = 50
*(p+3) = 50
*p+2 = 50
*(p+2) = 50
Output of following program?
# include <stdio.h>
void fun(int *ptr)
{
*ptr = 30;
}
int main()
{
int y = 20;
fun(&y);
printf("%d", y);
return 0;
}
20
Compiler Error
30
Run time Error
#include <stdio.h>
int main()
{
int *ptr;
int x;
ptr = &x;
*ptr = 0;
printf(" x = %dn", x);
printf(" ptr = %dn", *ptr);
*ptr += 5;
printf(" x = %dn", x);
printf(" ptr = %dn", *ptr);
(*ptr)++;
printf(" x = %dn", x);
printf(" ptr = %dn", *ptr);
return 0;
}
x = 0
*ptr = 0
x = 5
*ptr = 5
x = 6
*ptr = 6
x = garbage value
*ptr = 0
x = garbage value*ptr = 5
x = garbage value
*ptr = 6
x = 0
*ptr = 0
x = 5
*ptr = 5
x = garbage value
*ptr = garbage value
x = 0
*ptr = 0
x = 0
*ptr = 0
x = 0
*ptr = 0
Assume that float takes 4 bytes, predict the output of following program.
#include <stdio.h>
int main()
{
float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f ", *ptr2);
printf("%d", ptr2 - ptr1);
return 0;
}
90.500000 3
90.500000 12
10.00000 12
0.50000 12
The reason for using pointers in a Cprogram is
A
Pointers allow different functions to share and modify their local variables.
B
To pass large structures so that complete copy of the structure can be avoided.
C
Pointers enable complex “linked" data structures like linked lists and binary trees.
D
All Answers are correct
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
printf("%p\t%p", p, a);
}
a) Same address is printed
b) Different address is printed
c) Compile time error
d) Nothing
Assuming a 32 bit processor predict the output of the following program
int main()
{
int arri[] = {1, 2 ,3};
int *ptri = arri;
printf("%d ", sizeof(arri));
printf("%d ", sizeof(ptri));
return 0;
}
3 3
12 12
4 4
12 4
Is the NULL pointer same as an uninitialised pointer?
Yes
No
Predict the Output of the Following
#include<stdio.h>
void f(int p, int q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main()
{
f(&i, &j);
printf("%d %d \n", i, j);
getchar();
return 0;
}
(A) 2 2
(B) 2 1
(C) 0 1
(D) 0 2
Predict output of following program
Predict the output of the following code
#include <stdio.h>
int fun(int n)
{
if (n == 4)
return n;
else return 2*fun(n+1);
}
int main()
{
printf("%d ", fun(2));
return 0;
}
4
8
16
12
