ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
"its my thinking that , printf works on base address" if i am correct than please say ::: yes/no !
now i tell you why i am thinking this , because printf(2+"hello");
so here printf() is fetching the base address of "hello" string and adding "+2" means 8 bytes in it !
and the output is :: llo
Last edited by tushar_pandey; 07-25-2012 at 10:15 PM.
Sorry , but how can you say that printf("gcchen"); is perfectly legal , and if it is perfectly legal than why this statement does not need the format specifier !
because in
> printf("pan64","NevemTeve");
Perfectly legal, but compilation warning may arise: there is no %-sequences in format string, so the second argument is ignored.
this statement it needs format specifier .
Last edited by tushar_pandey; 07-25-2012 at 11:38 PM.
Sir , "Sorry , but how can you say that printf("gcchen"); is perfectly legal , and if it is perfectly legal than why this statement does not need the format specifier !" // this line is clear , after reading this syntax "String that contains the text to be written to stdout . It can optionally contain embedded format tags that are substituted by the values specified in subsequent argument(s) and formatted as requested." from "http://v2.cplusplus.com/reference/cl...cstdio/printf/"
but why this is illegal .... printf("hello","nevemteve");
Last edited by tushar_pandey; 07-26-2012 at 12:15 AM.
Hello tusshar,
check out this pgm.... find out printf's working..........
#include <stdio.h>
int main ()
{
printf ("\ngcchen");
printf ("\ngcc%xhen"); // will get junk value o/p for %x here
printf("\npan64","NevemTeve");
printf("\npan64%s","NevemTeve");
}
but why this is illegal .... printf("hello","nevemteve");
No, it is not illegal, it works, just the second argument ("nevemteve") will not be used at all, will be ignored.
You can also try: printf("hello", 1,2,54,7, "fe","ignored", "some more", "anything") and any number of arguments are legal, but will be ignored.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.