ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
#define min((a),(b))  ((a)<(b))?(a):(b)
	main()
	{
	 int i=0,a[20],*ptr;
	 ptr=a;
	 while(min(ptr++,&a[9])<&a[8]) i=i+1;
	 printf("i=%d\n",i);}
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: #define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}
Answer
# 1
5
 
Is This Answer Correct ?    2 Yes 2 No
Guest
 
  Re: #define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}
Answer
# 2
here the value will be 3.

EXPLANATION:
here the #define macros will blindly substitute the values
in the while loop before compailation.. then when it compails...
1)we will have the expanded macros like this:
            while((ptr++<&a[9]?ptr++:&a[9])<&a[8])
i++;

hrer when the loop runs for the first time ptr will
increment by 2 since it is a integer type, which allocates 2
bytes.
first see the layout:
 10  12  14    16    18   20   22    24   26   28  30 ..... 
|   |   |    |     |     |    |     |    |    |   |   |    
  0   1    2     3    4     5   6     7    8    9   10 ....
0,1,2,3 represents index values...
10,12,14 represents addresses....
so the ptr variable will have the base address of array a.
when comin to while loop, it gets incremented to the next
location , address is 12,and go and check wit the address of
&a[9] in our case it is 28. so naturally it wil become true
so it executes the statement after ? symbol.. again in that
ptr++ is given so again ptr will be incremented to 14.. so
14 will be compared with &a[8] ,likely to be 26. it is TRUE
so the whole loop is true ,so i gets incremented so i=1.
next time ptr adds to 16 and then 16<28 and again ptr gets
incremented to 18 and 18<26 and whole while becomes true so
i will become 2.
similarly it will again increments ptr to 20 an dthis
becomes true an ptr again gets incremented to 22 and it
checks whether 22<26! yes, it will increment i to 3.

IMPORTANT:
after that it increments ptr to 24 and executes the
operation after ? operator and again ptr will have 26, this
26 is checked with 26 (&a[8]) the whole while loop becomes
false...
so it wont go to i++, it will printf the printf statement so
i=3.
 
Is This Answer Correct ?    2 Yes 1 No
Vignesh1988i
 
 
 
  Re: #define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}
Answer
# 3
4
 
Is This Answer Correct ?    0 Yes 0 No
Bj
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
if the address of a[1,1] and a[2,1] are 1000 and 1010 respectively and each occupies 2 bytes then the array has been stored in what order?  3
How do you write a program which produces its own source code as its output?  2
Write a Program to print this triangle: * ** * **** * ****** * ******** * ********** use two nested loops. TCS5
Explain in detail how strset (string handling function works )pls explain it with an example.  1
1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.  2
how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com Honeywell3
given the piece of code int a[50]; int *pa; pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5) TCS5
What character terminates all strings composed of character arrays? 1) 0 2) . 3) END  3
what is mallloc()?how it works? Excel3
What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value. TCS7
What is the difference between null pointer and the void pointer?  2
what is the size of an integer variable?  1
write a 'c' program to sum the number of integer values  5
Write a C++ program without using any loop (if, for, while etc) to print numbers from 1 to 100 and 100 to 1;  7
How to write a program for swapping two strings without using 3rd variable and without using string functions. iGate5
int arr[] = {1,2,3,4} int *ptr=arr; *(arr+3) = *++ptr + *ptr++; Final contents of arr[] Hughes4
How would you find a cycle in a linked list?  2
pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used. Persistent4
I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.  1
Reverse a string word by word??  6
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com