#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
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 |
#include<stdio.h> int f(int,int); int main() { printf("%d",f(20,1)); return 0; } int f(int n,int k) { if(n==0) return 0; else if(n%2)return f(n/2,2*k)+k; else return f(n/2,2*k)-k; } how this program is working and generating output as 9....?
Write a program or provide a pseudo code to flip the 2nd bit of the 32 bit number ! (Phone Screen)
write a c program to print a given number as odd or even without using loop statements,(no if ,while etc)
what is the use of a array in c
if p is a string contained in a string?
how to use enum datatype?Please explain me?
What is the advantage of using #define to declare a constant?
0 Answers Agilent, ZS Associates,
value = 0xabcd; for (loop = 1; (value >> 1) & 1 | loop & 1; loop++) { foo(); if (loop & 1) value >>= 1; } how many times is foo() executed?
what is develop in c language
3.write a simple program that will output your name,phone number,e-mail address,and academic major on separate lines 1.create an account and a personal directory for your work b.find out how to create a subdirectory on your system.create one called info c.you will use a text editor to type in your programs and data files.some C systems have a built in text editor;others do not.Find out what text editor you will be using and how to access it.create a text file(not a program) containing your name ,address,and telephone number on separate lines.Next,write the brand of computer you are using and the name of the text editor.Then write a paragraph that describes your past experience with computers.save this file in your info directory. d. find out how to print a file on your system .print out and turn in the file you created in (c).
what is the maximum limit of row and column of a matrix in c programming. in linux .
With the help of using classes, write a program to add two numbers.