Test on ‘C’ Programming
Time Duration: 1 Hr.
Total Marks: 30
Write the output of the following programs: (Assume the required headers are included)
1 : What is the out put if any syntax error specify
main(){
#define ABC 20
#define XYZ 10
#define XXX ABC - XYZ
int a;
a = XXX * 10;
printf("%d\n", a); }
2 : Give the output: main(){
int a = 0xFF20;
char *p;
p=(char *)&a;
printf("%x\n", *p); }
3 : main(){ int cnt = 5, a;
do {
a /= cnt;
} while (cnt --);
printf ("%d\n", a); }
4 : struct bits { unsigned long a:3;
char c:3; }bits;
main(){
struct bits *ptr=&bits;
bits.a=10;
printf("%u\n",ptr->a);
printf("%d\n",sizeof(bits));}
5 : main(){ int k = 5,m;
m= (k < 5 && k++/0 || ++k <= 8);
printf("%d %d\n", k,m); }
6 : void fn(int, int); main(){
int a = 5;
fn(a=7, a); }
void fn(int a, int b){
printf("Fn : a = %d \t b = %d\n", a, b); }
7 : Write the output of this program main(){
int *a, *s, i;
s = a = (int *) malloc( 4 * sizeof(int));
for (i=0; i<4; i++) *(a+i) = i * 10;
printf("%d\n", *s++);
printf("%d\n", (*s)++);
printf("%d\n", *s);
printf("%d\n", *++s);
printf("%d\n", ++*s);}
8 : static void fn(int); main(){
extern int val;
while (val --)
fn(val);
printf("%d\n", val);
}
static void fn(int v){
static int val = 0;
for (; val < 5; val ++) printf("%d\n", val);}
extern int val = 5
9 : main(){ typedef union {
int a;
char b[10];
float c;
} Union;
Union x, y = { 100 };
x.a = 50;
strcpy (x.b, "hello");
x.c = 21.50;
printf ("Union x : %d\t %s\t %f\n", x.a, x.b, x.c);
printf ("Union Y : %d\t %s\t %f\n", y.a, y.b, y.c); }
10 : main(){ struct Data {
int a;
int b;
} y[4] = { 1, 10, 3, 30, 2, 20, 4, 40};
struct Data *x = y;
int i;
for(i=0; i<4; i++) {
x->a = x->b, ++x ->b;
printf("%d %d\t", y[i].a, y[i].b); } }
11 : main(){ typedef struct {
int a;
int b;
int c;
char ch;
int d;
}xyz;
typedef union {
xyz X;
char y[100];
Time Duration: 1 Hr.
Total Marks: 30
Write the output of the following programs: (Assume the required headers are included)
1 : What is the out put if any syntax error specify
main(){
#define ABC 20
#define XYZ 10
#define XXX ABC - XYZ
int a;
a = XXX * 10;
printf("%d\n", a); }
2 : Give the output: main(){
int a = 0xFF20;
char *p;
p=(char *)&a;
printf("%x\n", *p); }
3 : main(){ int cnt = 5, a;
do {
a /= cnt;
} while (cnt --);
printf ("%d\n", a); }
4 : struct bits { unsigned long a:3;
char c:3; }bits;
main(){
struct bits *ptr=&bits;
bits.a=10;
printf("%u\n",ptr->a);
printf("%d\n",sizeof(bits));}
5 : main(){ int k = 5,m;
m= (k < 5 && k++/0 || ++k <= 8);
printf("%d %d\n", k,m); }
6 : void fn(int, int); main(){
int a = 5;
fn(a=7, a); }
void fn(int a, int b){
printf("Fn : a = %d \t b = %d\n", a, b); }
7 : Write the output of this program main(){
int *a, *s, i;
s = a = (int *) malloc( 4 * sizeof(int));
for (i=0; i<4; i++) *(a+i) = i * 10;
printf("%d\n", *s++);
printf("%d\n", (*s)++);
printf("%d\n", *s);
printf("%d\n", *++s);
printf("%d\n", ++*s);}
8 : static void fn(int); main(){
extern int val;
while (val --)
fn(val);
printf("%d\n", val);
}
static void fn(int v){
static int val = 0;
for (; val < 5; val ++) printf("%d\n", val);}
extern int val = 5
9 : main(){ typedef union {
int a;
char b[10];
float c;
} Union;
Union x, y = { 100 };
x.a = 50;
strcpy (x.b, "hello");
x.c = 21.50;
printf ("Union x : %d\t %s\t %f\n", x.a, x.b, x.c);
printf ("Union Y : %d\t %s\t %f\n", y.a, y.b, y.c); }
10 : main(){ struct Data {
int a;
int b;
} y[4] = { 1, 10, 3, 30, 2, 20, 4, 40};
struct Data *x = y;
int i;
for(i=0; i<4; i++) {
x->a = x->b, ++x ->b;
printf("%d %d\t", y[i].a, y[i].b); } }
11 : main(){ typedef struct {
int a;
int b;
int c;
char ch;
int d;
}xyz;
typedef union {
xyz X;
char y[100];
}abc;
printf("sizeof xyz = %d sizeof abc = %d\n",
sizeof(xyz), sizeof(abc)); }
12 : Give the output:
main(){
printf("\nab");
printf("\bsi");
printf("\rha");}
13 : main(){ int *a, *savea, i;
savea = a = (int *) malloc(4 * sizeof(int));
for (i=0; i<4; i++) *a++ = 10 * i;
for (i=0; i<4; i++) {
printf("%d\n", *savea);
savea += sizeof(int); } }
14: What will be the value of i & j after the loop is executed?
for(i=0,j=0;i<5,j<25;i++,j++)
(a) i=4,j=24 (b) i=24,j=24
(c) i=25,j= 25 (d) i=5,j=25
15:
int main(){
unsigned int i=1,j;
for(j=0;j<4;j++){
i=i<<j;
printf(" %d ",i);
}
16:
Consider a linked list of n elements which is pointed by an external pointer. What is the time taken to delete the element which is successor of the element pointed to by a given pointer ?
a O(1).
b.O(log2 n)
c.O(n)
d.O(n log2 n)
17: What is the out put if any syntax error correct and specify
main(){
int i=0;
for(i=0;i<20;i++) {
switch(i)
{
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i); } }
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
18: #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a); }
19:char (*(*x())[])();
20: #define f(g,g2) g##g2
main() {
int var12=100;
printf("%d",f(var,12)); }
21: main(){
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i); }
22: main( ){
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);}
23:Give the output:
main() {
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }
24: int i=10;
main() {
extern int i; {
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);}
printf("%d",i); }
printf("%d",i);
}
25:which one of the following are not portable:
a)int
b)float
c)both a and b
d)only a
26: int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
27 :main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello"); }
28: main(){
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);}
29:main(){
signed char i=0;
for(;i>=0;i++) ;
printf("%d\n",i); }
30: main(){
int i=4,j=7;
j = j || i++ && printf("YOU CAN");
printf("%d %d", i, j);}
printf("sizeof xyz = %d sizeof abc = %d\n",
sizeof(xyz), sizeof(abc)); }
12 : Give the output:
main(){
printf("\nab");
printf("\bsi");
printf("\rha");}
13 : main(){ int *a, *savea, i;
savea = a = (int *) malloc(4 * sizeof(int));
for (i=0; i<4; i++) *a++ = 10 * i;
for (i=0; i<4; i++) {
printf("%d\n", *savea);
savea += sizeof(int); } }
14: What will be the value of i & j after the loop is executed?
for(i=0,j=0;i<5,j<25;i++,j++)
(a) i=4,j=24 (b) i=24,j=24
(c) i=25,j= 25 (d) i=5,j=25
15:
int main(){
unsigned int i=1,j;
for(j=0;j<4;j++){
i=i<<j;
printf(" %d ",i);
}
16:
Consider a linked list of n elements which is pointed by an external pointer. What is the time taken to delete the element which is successor of the element pointed to by a given pointer ?
a O(1).
b.O(log2 n)
c.O(n)
d.O(n log2 n)
17: What is the out put if any syntax error correct and specify
main(){
int i=0;
for(i=0;i<20;i++) {
switch(i)
{
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i); } }
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
18: #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a); }
19:char (*(*x())[])();
20: #define f(g,g2) g##g2
main() {
int var12=100;
printf("%d",f(var,12)); }
21: main(){
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i); }
22: main( ){
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);}
23:Give the output:
main() {
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }
24: int i=10;
main() {
extern int i; {
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);}
printf("%d",i); }
printf("%d",i);
}
25:which one of the following are not portable:
a)int
b)float
c)both a and b
d)only a
26: int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
27 :main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello"); }
28: main(){
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);}
29:main(){
signed char i=0;
for(;i>=0;i++) ;
printf("%d\n",i); }
30: main(){
int i=4,j=7;
j = j || i++ && printf("YOU CAN");
printf("%d %d", i, j);}
-------------------------------------------------------------------------------------------------------------------