JAYASHREE ORACLE CERTIFIED JAIN UNIVERSITY

Friday, September 24, 2010

C For Swimmers
______________

Topic : Discovering C
_____ _____________

*************************************************************************************************
* NOTE : All the programs are tested under Turbo C/C++ compilers. *
* It is assumed that, *
* *=> Programs run under DOS environment, *
* *=> The underlying machine is an x86 system, *
* *=> Necessary header files are included. *
* *=> Program is compiled using Turbo C/C++ compiler. *
* The program output may depend on the information based on this assumptions. *
* (For example sizeof(int) = 2 bytes may be assumed). *
*************************************************************************************************


[Q001]. The following code is not well-written. What does the program do ?
void
main(
){int a=1,
b=2,c=3,d=4;printf("%d %d",
a,b);printf(
" %d %d",c,d);
}

(a)Run-Time Error (b)Compile-Time Error (c)1 2 3 4 (d)None of these
Ans. (d)
_________________________________________________________________________________________________

[Q002]. What will be the output of the following program :
void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
(a)0 3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3 0
Ans. (c)
_________________________________________________________________________________________________

[Q003]. What will be the output of the following program :
void main()
{
int a=1,b=2,c=3,d=4,e;
e=(a,a)+(b,c)+(c,d)-(d,b);
printf("%d",e);
}
(a)Compile-Time Error (b)10 (c)6 (d)2
Ans. (c)
_________________________________________________________________________________________________

[Q004]. What will be the output of the following program :
void main()
{
float val=2.;
printf("%.2",val);
}
(a)Compile-Time error (b)2.00 (c)%.2 (d)2.000000
Ans. (b)
_________________________________________________________________________________________________

[Q005]. What will be the output of the following program :
void main()
{
int a=5;
int b=6;;
int c=a+b;;;
printf("%d",c);;;;
}
(a)Compile-Time Error (b)Run-Time Error (c)11 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q006]. What will be the output of the following program :
void main()
{
int i,j;
for (i=1; i<=3; i++)
for (j=1; j<3;>
{
if (i == j)
continue;
if ((j % 3) > 1)
break;
printf("%d",i);
}
}
Ans.
_________________________________________________________________________________________________

[Q007]. What will be the output of the following program :
#define swap(a,b) temp=a; a=b; b=temp;
void main()
{
static int a=5,b=6,temp;
if (a > b)
swap(a,b);
printf("a=%d b=%d",a,b);
}
(a)a=5 b=6 (b)a=6 b=5 (c)a=6 b=0 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q008]. What will be the output of the following program :
void main()
{
unsigned int val=5;
printf("%u %u",val,val-11);
}
(a)Compile-Time error (b)5 -6 (c)5 65530 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q009]. What will be the output of the following program :
void main()
{
int x=4,y=3,z=2;
*&z*=*&x**&y;
printf("%d",z);
}
(a)Compile-Time error (b)Run-Time Error (c)24 (d)Unpredictable
Ans. (c)
_________________________________________________________________________________________________

[Q010]. What will be the output of the following program :
void main()
{
int i=5,j=5;
i=i++*i++*i++*i++;
printf("i=%d ",i);
j=++j*++j*++j*++j;
printf("j=%d",j);
}
(a)Compile-Time Error (b)i=1680 j=1680 (c)i=629 j=6561 (d)i=1681 j=3024
Ans. (c) Compiler dependent
_________________________________________________________________________________________________

[Q011]. What will be the output of the following program :
void main()
{
int i=5;
printf("%d %d %d %d %d",++i,i++,i++,i++,++i);
}
(a)Compile-Time Error (b)10 9 8 7 6 (c)9 8 7 6 6 (d)10 8 7 6 6
Ans. (d)
_________________________________________________________________________________________________

[Q012]. What will be the output of the following program :
void main()
{
unsigned ch='Y';
printf("%d",sizeof ch);
}
(a)Compile-Time Error (b)2 (c)4 (d)1
Ans. (b)
_________________________________________________________________________________________________

[Q013]. What will be the output of the following program :
void main()
{
int a=5;
printf("%d");
}
(a)Compile-Time Error (b)5 (c)Unpredictable (d)No Output
Ans. (b)
_________________________________________________________________________________________________

[Q014]. What will be the output of the following program :
void main()
{
int a=5,b=6;
printf("%d");
}
(a)Compile-Time Error (b)5 (c)6 (d)Unpredictable
Ans. (c)
_________________________________________________________________________________________________

[Q015]. What will be the output of the following program :
void main()
{
int a=5,b=6,c=7;
printf("%d %d %d");
}
(a)Compile-Time Error (b)5 6 7 (c)7 6 5 (d)Unpredictable
Ans. (c)
_________________________________________________________________________________________________

[Q016]. What will be the output of the following program :
#define Swap if (a != b) { \
temp=a; \
a = b; \
b = temp; \ //Swapping Done
}
void main()
{
int a=10,b=5,temp;
Swap;
printf("a=%d a=%d",a,b);
}
(a)Compile-Time Error (b)a=5 b=10 (c)a=10 b=5 (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q017]. What will be the output of the following program :
void main()
{
int val=50;
void *ptr;
ptr=&val;
printf("%d %d",val,*(int *)ptr);
}
(a)Compile-Time Error (b)50 50 (c)50 0 (d)None of these
Ans. (b)
_________________________________________________________________________________________________

[Q018]. What will be the output of the following program :
void main()
{
int a=5,b=6;
Printf("%d %d %d",a,b,--a*++b);
}
(a)Compile-Time Error (b)5 6 30 (c)4 7 28 (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q019]. What will be the output of the following program :
void main()
{
int val=5;
void *ptr;
*(int *)ptr=5;
val=ptr;
printf("%d %d",*(int *)val,*(int *)ptr);
}
(a)Compile-Time Error (b)Unpredictable (c)5 5 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q020]. What will be the output of the following program :
void main()
{
int val=2;
val = - --val- val--- --val;
printf("%d",val);
}
(a)Compile-Time Error (b)3 (c)-1 (d)0
Ans. (c)
_________________________________________________________________________________________________

[Q021]. What will be the output of the following program :
void main()
{
int i,n=10;
for (i=1; i
printf("%d\n",n-i);
}
(a)84 (b)840 (c)852 (d)864
Ans. (c)
_________________________________________________________________________________________________

Thanx for using "C For Swimmers".

Regarding this material, you can send Bug Reports, Suggestions, Comments,etc. jayukudari@gmail.com

No comments:

Post a Comment