
By : Nanda Kishor K N                                      Mail ID : nandakishorkn@rediffmail.com
_________________________________________________________________________________________________

                                       C For Swimmers
                                       ______________

      If u don't know how to swim, learn it now. Otherwise participate in the competition.

_________________________________________________________________________________________________

		                 Topic : Exploring C (Part II)
                		 _____   ___________

*************************************************************************************************
* 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]. What will be the output of the following program :
	int func(int *ptr,int a,int b)
	{
	  return (a+b);
	  *ptr=25;
	}
	void main()
	{
	  int var=7,sum;
	  sum=func(&var,5,6);
	  printf("%d %d",sum,var);
	}

(a)Compile-Time Error	(b)11 25			(c)11 7			(d)None of these
Ans. (c) 		
_________________________________________________________________________________________________
	
[Q002]. What will be the output of the following program :
	int func(int *ptr,int a,int b)
	{
	  return (a+b);
	  *ptr=25;
	  return *ptr;
	}
	void main()
	{
	  int var=7;
	  sum=func(&var,5,6);
	  printf("%d %d",sum,var);
	}

(a)Compile-Time Error	(b)11 25			(c)11 7			(d)25 7
Ans. (c) 	
_________________________________________________________________________________________________

[Q003]. What will be the output of the following program :
	int func(int *ptr,int a,int b)
	{
	  *ptr=25;
	  return *ptr;
	  return (a+b);
	}
	void main()
	{
	  int var=7;
	  sum=func(&var,5,6);
	  printf("%d %d",sum,var);
	}

(a)Compile-Time Error	(b)11 25			(c)11 7			(d)25 25
Ans. (d)
_________________________________________________________________________________________________
	
[Q004]. What will be the output of the following program :
	#include <stdio.h>
	#define ToStr(s) #s
	#define Swap(x,y) y##x
	void Swap(in,ma)()
	{
	  if (printf(ToStr("Friends"))){}
	}

(a)Compile-Time Error	(b)"Friends"			(c)Friends		(d)None of these
Ans. (b) 
_________________________________________________________________________________________________

[Q005]. What will be the output of the following program :
	void main()
	{
	  int a=(5,a=50)/a++;
	  printf("%d",a);
	}

(a)51			(b)0				(c)6			(d)1
Ans. (d) 
_________________________________________________________________________________________________

[Q006]. What will be the output of the following program :
	void main()
	{
	  int a=(5,a=50)/++a;
	  printf("%d",a);
	}
(a)51			(b)0				(c)6			(d)1
Ans. (b) 
_________________________________________________________________________________________________
	
[Q007]. What will be the output of the following program :
	void main()
	{
	  int a=7;
	  if ((++a < 7) && (++a < 9) && (++a < 25)
	  ;
	  printf("%d",a);
	}

(a)7			(b)8				(c)9			(d)10
Ans. (b) 
_________________________________________________________________________________________________

[Q008]. What will be the output of the following program :
	void main()
	{
	  int a=7;
	  if ((++a < 7) && (a++ < 9) && (++a < 10);
	  printf("%d",a);
	}

(a)7			(b)8				(c)9			(d)10
Ans. (d) 
_________________________________________________________________________________________________
	
[Q009]. What will be the output of the following program :
	main()
	{
	  for ( ; ; )
	      main();
	}
(a)Compile-Time error	(b)Run-Time Error		(c)Infinite Loop	(d)None of these
Ans. (c)  	
_________________________________________________________________________________________________

[Q010]. What will be the output of the following program :
	void main()
	{
	  int a=0,b=1,c;
	  c = a=0 ? (a=1) : (b=2);
	  printf("%d %d %d",a,b,c);
	}

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

[Q011]. What will be the output of the following program :
	void main()
	{
	  int a=5,b=1,c;
	  c = a ? a=1 : b=2;
	  printf("%d %d %d",a,b,c);
	}

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

[Q012]. What will be the output of the following program :
	main()
	{
	  unsigned _=5;
	  _=_--- ++_;
	  printf("%d",_);
	}
(a)Compile-Time Error	(b)5				(c)65535		(d)-1
Ans. (d) 
_________________________________________________________________________________________________	

[Q013]. What will be the output of the following program :
	main()
	{
	  unsigned _=5;
	  _=_--- ++_;
	  printf("%u",_);
	}
(a)Compile-Time Error	(b)5				(c)65535		(d)-1
Ans. (c) 
_________________________________________________________________________________________________	

[Q014]. What will be the output of the following program :
	int fun(int a,int b)
	{
	   #define NUM 5
	   return a+b;
	}
	main()
	{
	   printf("Sum=%d",fun(NUM,NUM));
	}

(a)Compile-Time Error	(b)Run-Time Error		(c)Sum=10		(d)None of these
Ans. (c)
_________________________________________________________________________________________________	

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

[Q016]. What will be the output of the following program :
	int add(int a,int b)
	{
	  return a+b;
	}
	main()
	{
	  int a=1,b=2;
	  printf("%d",add(add(add(a,b),add(a,b)),add(add(a,b),add(a,b))));
	}

(a)Garbage value	(b)Run-Time Error		(c)Compile-Time Error	(d)12
Ans. (d) 
_________________________________________________________________________________________________	

[Q017]. What will be the output of the following program :
	#define S(s)char x[]="Welcome to ";s
	#define P(s) #s
	#define Q(x)char x[]=#x
	#define A(x,y)y##x
	#define B(x,y)A(y,x)
	#define C(x,y)B(y,x)
	S(B(A(a,m),A(n,i))(){Q(C(B(A(n,e),d),B(A(r,f),i))s);B(A(t,
	s),B(A(c,r),A(y,p)))(C(B(A(n,e),d),B(A(r,f),i))s,P(c4swimmers)
	);B(A(r,p),B(A(n,i),A(f,t)))("%s%s",x,C(B(A(n,e),d),B(A(r,f),i))s)
	;B(A(e,r),B(A(u,t),A(n,r))) 0;})

(a)Compile-Time Error	(b)Welcome to c4swimmers	(c)Welcome to		(d)c4swimmers
Ans. (c) 
_________________________________________________________________________________________________	

[Q018]. What will be the output of the following program :
	void main()
	{
	  int a=5,b=6,c=7,d=8,e;
	  e = a ? b , c : c , d;
	  printf("%d",e);
	}

(a)Compile-Time Error	(b)6				(c)7			(d)8
Ans. (c) 
_________________________________________________________________________________________________	

[Q019]. What will be the output of the following program :
	void main()
	{
	  int a=5,b=6,c;
	  c++ = b % (b - a); 
	  printf("%d",c);
	}

(a)Compile-Time Error	(b)6				(c)7			(d)None of these
Ans. (a)
_________________________________________________________________________________________________	

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

				Thanx for using "C For Swimmers".
Regarding this material, you can send Bug Reports, Suggestions, Comments,etc. to nandakishorkn@rediffmail.com