NEW
Font size
WorksheetsOCS752_CP_MODEL 1_PART B (16.10.2020)
Total questions: 10
Worksheet time: 10mins
What is the output of this C code?
int main()
{
int i = 97, *p = &i;
foo(&p);
printf("%d ", *p);
return 0;
}
void foo(int **p)
{
int j = 2;
*p = &j;
printf("%d ", **p);
}
2 2
2 97
Undefined behaviour
Segmentation fault/code crash
What is the output of this C code?
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **m);
}
5 5 5
5 5 junk value
5 junk value
Run time error
Consider the following C-program:
filter_none
edit
play_arrow
brightness_4
double foo (double); /* Line 1 */ int main() { double da, db; // input da db = foo(da); } double foo(double a) { return a; }
The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:
no compile warning or error
some compiler-warnings not leading to unintended results
some compiler-warnings due to type-mismatch eventually leading to unintended results
compiler errors
Output of following program?
#include<stdio.h>
void dynamic(int s, ...)
{
printf("%d ", s);
}
int main()
{
dynamic(2, 4, 6, 8);
dynamic(3, 6, 9);
return 0;
}
2 3
Compiler Error
4 3
3 2
What is the output printed by the following program?
#include<stdio.h>
int f(int n, int k)
{
if (n == 0)
return 0;
else if (n % 2)
return f(n/2, 2*k) + k;
else return f(n/2, 2*k) - k;
}
int main ()
{
printf("%d", f(20, 1));
return 0;
}
5
8
9
20
Consider the following C function
void swap ( int x, int y )
{
int tmp;
tmp = x;
x= y;
y = tmp;
}
In order to exchange the values of two variables a and b:
Call swap (a, b)
Call swap (&a, &b)
swap(a, b) cannot be used as it does not return any value
swap(a, b) cannot be used as the parameters passed by value
Consider the following declaration :
struct addr {
char city[10];
char street[30];
int pin ;
};
struct {
char name[30];
int gender;
struct addr locate;
} person , *kd = &person ;
Then *(kd -> name +2) can be used instead of
person.name +2
kd -> (name +2 )
*((*kd).name + 2 )
either (A) or (B), but not (C)
What is the output of this program?
#include <stdio.h>
struct
{
int i;
float ft;
}decl;
int main(){
decl.i = 4;
decl.ft = 7.96623;
printf("%d %.2f", decl.i, decl.ft);
return 0;
}
4 7.97
4 7.96623
Compilation error
None of the above
The correct syntax to access the member of the ith structure in the array of structures is?
struct temp
{
int b;
}s[50];
s.b.[i];
s.[i].b;
s.b[i];
s[i].b;
A short integer occupies 2 bytes an, ordinary integer 4 bytes and a long integer occupies 8 bytes of memory
If a structure is defined as
struct TAB{
short a;
int b;
long c;
}TABLE[10];
the the total memory requirement for TABLE is
14
140
40
32
