You are here:

C/function(parameters)

Advertisement


Question

hello narendra

i m unable to understand this code.pls explain
how these parametrs are passing .
void pascal f(int i,int j,int k)

     {

     printf(“%d %d %d”,i, j, k);

     }

     void cdecl f(int i,int j,int k)

     {

     printf(“%d %d %d”,i, j, k);

     }

     main()

     {

     int i=10;

     f(i++,i++,i++);

     printf(" %d\n",i);

     i=10;

     f(i++,i++,i++);

     printf(" %d",i);

}
i was expecting
10 10 10 13
10 10 10 13

but Answer  is


     10 11 12 13

     12 11 10 13

make it clear
thank you
monika  

Answer
I don't understand what you are doing!
Why 2 functions with the same kind of body!?

You are passing i++ to a function.
So, the arguments will be processed from right to left.
And the function will be passed 12, 11 and 10.
And the same will be printed.

I don't see any confusion here.
Also, the two calls to the same function cannot print two different answers!

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.