Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


#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);}

Answers were Sorted based on User's Feedback



#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(mi..

Answer / guest

5

Is This Answer Correct ?    10 Yes 4 No

#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(mi..

Answer / vignesh1988i

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 ?    3 Yes 2 No

#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(mi..

Answer / bj

4

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Explain #pragma in C.

1 Answers  


Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

0 Answers  


What are the scope of static variables?

0 Answers  


What is malloc calloc and realloc in c?

0 Answers  


52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?

9 Answers  


why Language C is plateform dependent

3 Answers   Siemens, Wipro,


Struct(s) { int a; long b; } Union (u) {int a; long b; } Print sizeof(s)and sizeof(u) if sizeof(int)=4 and sizeof(long)=4

2 Answers   Mascot,


The differences between Windows XP and Windows Visa

8 Answers   HCL,


Give the rules for variable declaration?

0 Answers  


Explain what is wrong with this program statement? Void = 10;

0 Answers  


Does c have an equivalent to pascals with statement?

0 Answers  


please send me the code for multiplying sparse matrix using c

0 Answers  


Categories