1. What is the output of the following?
main()
{
struct s1 {
char *z;
int i;
struct s1 *p;
};
static struct s1 a[] = { {"Mysore",1,a+1},
{"Mangalore",2,a+2},
{"Mumbai",3,a}
};
struct s1 *ptr = a;
printf("\n%s",++(ptr->z));
printf("\n%s",a[(++ptr)->i].z);
printf("\n%s",a[--(ptr->p->i)].z);
}
a) ysore b) Mysore c) Mangalore d) Mysore
Mumbai umbai Mumbai Mangalore
Mumbai Mumbai umbai Mumbai
2. What is the output?
main()
{
int i=1;
{
int i=64;
label: printf("%d ",i);
i++;
if (i>100)
goto label1;
}
i++;
goto label;
label1: ;
}
a) Compiler error
b) Unpredictable
c) Numbers 64 through 100
d) Numbers 1 through 100
3. What is the output?
main()
{
#define SQR(x) x++ * ++x
int i = 3;
printf("\n %d %d \n",SQR(i),i * SQR(i));
}
a) 9 27
b) 35 60
c) 20 60
d) 15 175
4. What is the output of the following segment?
(Assume that table is stored from address 404)
main()
{
static float table[2][3] = {
{1.1,1.2,1.3},
{2.1,2.2,2.3}
};
printf("%u %u %u %u %u %f %f %f %f \n",table,
table+1,*(table+1),(*(table+1)+1),(*(table)+1),
*(*(table+1)+1),*(*(table)+1),*(*(table+1)),
*(*(table)+1)+1);
}
a) 404 405 405 406 406 2.2 2.1 2.2 2.3
b) 404 416 420 420 421 2.1 2.1 1.3 2.3
c) 404 405 405 420 408 2.2 1.2 2.1 2.2
d) 404 416 416 420 408 2.2 1.2 2.1 2.2
5.
#define MAX 10
#define MAXLEN MAX+1
main()
{
printf("%d",MAXLEN * 10);
}
a) 110
b) 20
c) 100
d) 101
6.
main()
{
int a = 10,b;
a >= 5 ? b = 100 : b = 200;
printf("%d",b);
}
a) 200
b) 100
c) 10
d) Compiler error
7.
main()
{
float a = 0.7;
if (a < 0.7)
printf("C");
else
printf("C++");
}
a) Compiler error
b) Run-time error
c) C
d) C++
8.
main()
{
float a = 0.7;
if (a < 0.7f)
printf("C");
else
printf("C++);
}
a) Compiler error
b) Run-time error
c) C
d) C++
9.
main()
{
printf("%c",7["Sundaram"]);
}
a) m
b) Compiler error
c) a
d) r
10.
main()
{
int a[1];
int i;
for (i = 0; i <= 1; i++) {
a[i] = 2 * i;
printf("%d %d\n",i,a[i]);
}
}
a) 0 0 b) 0 0 c) 0 0 d) 0 0
1 2 1 Junk value 1 2
2 4
11.
main()
{
int a[1];
int i;
printf("%u\n",&i);
for (i = 0; i <= 1; i++) {
a[i] = 2 * i;
printf("%d %d\n",i,a[i]);
}
}
a) Some address b) Some address
0 0 0 0
1 2 2 Junk value
c) Some address d) Some address
0 0 0 0
1 2
2 4
12.
main()
{
struct exam {
char name[20];
float avg;
};
struct exam student[10];
int i;
for (i = 0; i <= 9; i++)
scanf("%s %f",student[i].name,&student[i].avg);
printf("%d",i);
}
a) 10
b) 9
c) Compiler error
d) Run-time error
13.
main()
{
int b;
b = func(20);
printf("%d",b);
}
int func(int v)
{
a > 20 ? return 10 : return 20;
}
a) 10
b) 20
c) Compiler error
d) func not declared in main
14.
main()
{
extern int f(float);
int a;
a = f(2.9);
printf("%d",a);
}
int f(aa)
float aa;
{
return ((int) aa);
}
a) 2
b) Error
c) 3
d) 0
15.
#include
#include
main()
{
char c = 127;
printf("%d",++c);
}
a) stdio.h cannot be included more than once
b) -128
c) 128
d) 0
16.
main()
{
#ifdef TRUE
/* Error?
int a;
a = 10;
#else
int a;
a = 20;
#endif
printf("%d",a);
}
a) 20
b) 10
c) Error because unterminated comment
d) Error since preprocessor directives
must precede all declarations
17.
main()
{
printf(5 + "C test");
}
a) Error
b) C test
c) test
d) t
18.
main()
{
int arr[] = {12,14,15,16,17};
/* Assume thar arr[] begins at address 65000 */
printf("%u %u ",arr+1,&arr+1);
}
a) 65002 65010
b) 65001 65001
c) 65001 65005
d) You cannot take the address of an array
19.
main()
{
struct man {
char *n;
int age;
};
struct man m1 = {"Jekyl",50};
struct man m2 = m1;
strupr(m2.n);
printf("\n%s\n",m1.n);
}
a) Jekyl
b) jekyl
c) JEKYL
d) Error
20.
main()
{
printf("%d %d %d",sizeof(3),sizeof('3'),sizeof("3"));
}
a) 2 1 2
b) 2 2 2
c) 1 1 1
d) 2 1 1
ANSWERS
-------
1. a 2. c 3. b 4. d 5. b
6. d 7. c 8. d 9. a 10. a
11. b 12. d 13. c 14. b 15. b
16. c 17. d 18. a 19. c 20. b
main()
{
struct s1 {
char *z;
int i;
struct s1 *p;
};
static struct s1 a[] = { {"Mysore",1,a+1},
{"Mangalore",2,a+2},
{"Mumbai",3,a}
};
struct s1 *ptr = a;
printf("\n%s",++(ptr->z));
printf("\n%s",a[(++ptr)->i].z);
printf("\n%s",a[--(ptr->p->i)].z);
}
a) ysore b) Mysore c) Mangalore d) Mysore
Mumbai umbai Mumbai Mangalore
Mumbai Mumbai umbai Mumbai
2. What is the output?
main()
{
int i=1;
{
int i=64;
label: printf("%d ",i);
i++;
if (i>100)
goto label1;
}
i++;
goto label;
label1: ;
}
a) Compiler error
b) Unpredictable
c) Numbers 64 through 100
d) Numbers 1 through 100
3. What is the output?
main()
{
#define SQR(x) x++ * ++x
int i = 3;
printf("\n %d %d \n",SQR(i),i * SQR(i));
}
a) 9 27
b) 35 60
c) 20 60
d) 15 175
4. What is the output of the following segment?
(Assume that table is stored from address 404)
main()
{
static float table[2][3] = {
{1.1,1.2,1.3},
{2.1,2.2,2.3}
};
printf("%u %u %u %u %u %f %f %f %f \n",table,
table+1,*(table+1),(*(table+1)+1),(*(table)+1),
*(*(table+1)+1),*(*(table)+1),*(*(table+1)),
*(*(table)+1)+1);
}
a) 404 405 405 406 406 2.2 2.1 2.2 2.3
b) 404 416 420 420 421 2.1 2.1 1.3 2.3
c) 404 405 405 420 408 2.2 1.2 2.1 2.2
d) 404 416 416 420 408 2.2 1.2 2.1 2.2
5.
#define MAX 10
#define MAXLEN MAX+1
main()
{
printf("%d",MAXLEN * 10);
}
a) 110
b) 20
c) 100
d) 101
6.
main()
{
int a = 10,b;
a >= 5 ? b = 100 : b = 200;
printf("%d",b);
}
a) 200
b) 100
c) 10
d) Compiler error
7.
main()
{
float a = 0.7;
if (a < 0.7)
printf("C");
else
printf("C++");
}
a) Compiler error
b) Run-time error
c) C
d) C++
8.
main()
{
float a = 0.7;
if (a < 0.7f)
printf("C");
else
printf("C++);
}
a) Compiler error
b) Run-time error
c) C
d) C++
9.
main()
{
printf("%c",7["Sundaram"]);
}
a) m
b) Compiler error
c) a
d) r
10.
main()
{
int a[1];
int i;
for (i = 0; i <= 1; i++) {
a[i] = 2 * i;
printf("%d %d\n",i,a[i]);
}
}
a) 0 0 b) 0 0 c) 0 0 d) 0 0
1 2 1 Junk value 1 2
2 4
11.
main()
{
int a[1];
int i;
printf("%u\n",&i);
for (i = 0; i <= 1; i++) {
a[i] = 2 * i;
printf("%d %d\n",i,a[i]);
}
}
a) Some address b) Some address
0 0 0 0
1 2 2 Junk value
c) Some address d) Some address
0 0 0 0
1 2
2 4
12.
main()
{
struct exam {
char name[20];
float avg;
};
struct exam student[10];
int i;
for (i = 0; i <= 9; i++)
scanf("%s %f",student[i].name,&student[i].avg);
printf("%d",i);
}
a) 10
b) 9
c) Compiler error
d) Run-time error
13.
main()
{
int b;
b = func(20);
printf("%d",b);
}
int func(int v)
{
a > 20 ? return 10 : return 20;
}
a) 10
b) 20
c) Compiler error
d) func not declared in main
14.
main()
{
extern int f(float);
int a;
a = f(2.9);
printf("%d",a);
}
int f(aa)
float aa;
{
return ((int) aa);
}
a) 2
b) Error
c) 3
d) 0
15.
#include
#include
main()
{
char c = 127;
printf("%d",++c);
}
a) stdio.h cannot be included more than once
b) -128
c) 128
d) 0
16.
main()
{
#ifdef TRUE
/* Error?
int a;
a = 10;
#else
int a;
a = 20;
#endif
printf("%d",a);
}
a) 20
b) 10
c) Error because unterminated comment
d) Error since preprocessor directives
must precede all declarations
17.
main()
{
printf(5 + "C test");
}
a) Error
b) C test
c) test
d) t
18.
main()
{
int arr[] = {12,14,15,16,17};
/* Assume thar arr[] begins at address 65000 */
printf("%u %u ",arr+1,&arr+1);
}
a) 65002 65010
b) 65001 65001
c) 65001 65005
d) You cannot take the address of an array
19.
main()
{
struct man {
char *n;
int age;
};
struct man m1 = {"Jekyl",50};
struct man m2 = m1;
strupr(m2.n);
printf("\n%s\n",m1.n);
}
a) Jekyl
b) jekyl
c) JEKYL
d) Error
20.
main()
{
printf("%d %d %d",sizeof(3),sizeof('3'),sizeof("3"));
}
a) 2 1 2
b) 2 2 2
c) 1 1 1
d) 2 1 1
No comments:
Post a Comment