Tuesday, July 28, 2009

What is prototype of printf statement in this case?

int printf(const char*restrict format,...);


what is this restricted format and ,... ??





what is the prototype of printf statement in case mentioned below





printf("%d%d%d%d",a,b,c,d);


i am mean we can declare any values say a=2,b=3,c=7 d=1000 HOW is it working????????Please explain briefly?

What is prototype of printf statement in this case?
Doesn't know. But i think printf() is something special. Very special as a main(). It takes the first argument a char pointer.


Then it searches for % inside the string and accordingly extracts the data passed to it and processes it. Then it sends it to the stdout.





My doubt is that how printf() accepts different number of data at different times eventhough C does not support polymorphism.





printf() is very different. It is similar to a program designed in assembly. That gets arguments. The first argument char must be its true argument.





Then it should use some other method of its own to get the data.It will know the no. of data passed to it by the number of %.





Its all my ideas and it can be wrong. (Mostly they are wrong)
Reply:be elaborated man


what do u want to ask


printf is supposed to work with all of the data types


prototype doesnt make sense to me


can u ask the ques in some diff way
Reply:%d stands for decimel.


you also have strings, chars and floats among others.





so lets say:


str = "hello"


a = 3





printf("Test %s, %d ... ",str, a);





will give





Test hello, 3 ...
Reply:The ... is a special variable type. It must appear at the end of a function signature, it is a pointer to a variable number of arguments. I think the object is varargs, the compiler is capable of handling this and passing any number of arguments to printf and other similar functions that use the ... There should be one argument for each % passed in the character array.


No comments:

Post a Comment