answer this plz

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 3
Reputation: Shillz is an unknown quantity at this point 
Solved Threads: 0
Shillz Shillz is offline Offline
Newbie Poster

answer this plz

 
0
  #1
Oct 18th, 2009
how can we use a printf statement without a semicolon???
this was a question asked during an interview of a computer engineering student.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training
 
0
  #2
Oct 18th, 2009
May be a printf within a printf would do the trick.Because the inner printf doesn't require the semicolon.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,493
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso
 
0
  #3
Oct 18th, 2009
Here the statement finishes with a comma, not a semicolon:
  1. #include <iostream>
  2.  
  3. int main() {
  4. printf("Hello"),
  5. getchar();
  6. return 0;
  7. }
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: Shillz is an unknown quantity at this point 
Solved Threads: 0
Shillz Shillz is offline Offline
Newbie Poster
 
0
  #4
Oct 18th, 2009
csurfer...howz that possible...i mean can u give the syntax plz...


william...this isnt working..i tried it out...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,493
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso
 
0
  #5
Oct 18th, 2009
Ahh, that's C+ code, didn't realize which forum this was. Try this:
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. printf("Hello"),
  5. getchar();
  6. return 0;
  7. }
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 6
Reputation: vandna is an unknown quantity at this point 
Solved Threads: 0
vandna vandna is offline Offline
Newbie Poster
 
-3
  #6
Oct 18th, 2009
use this one...
#include<stdio.h>
main()
{
printf("i am an engg"),
getchar();
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 26
Reputation: nomemory is an unknown quantity at this point 
Solved Threads: 5
nomemory nomemory is offline Offline
Light Poster
 
0
  #7
Oct 18th, 2009
  1. #include <stdio.h>
  2. #define PRINT_STRING(_s) printf("%s",_s)
  3.  
  4. int main() {
  5. PRINT_STRING("string");
  6. return (0);
  7. }

You can also try this.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 26
Reputation: nomemory is an unknown quantity at this point 
Solved Threads: 5
nomemory nomemory is offline Offline
Light Poster
 
0
  #8
Oct 18th, 2009
  1. #include <stdio.h>
  2. #define PRINT_STRING(_s) printf("%s",_s)
  3.  
  4. int main() {
  5. PRINT_STRING("string");
  6. return (0);
  7. }

You can also try this.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,493
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 123
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso
 
0
  #9
Oct 18th, 2009
That's not correct, that just turns into:
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. printf("%s","string");
  5. return (0);
  6. }
Once the preprocessor's done.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training
 
0
  #10
Oct 18th, 2009
Originally Posted by Shillz View Post
csurfer...howz that possible...i mean can u give the syntax plz...


william...this isnt working..i tried it out...
Well what I meant was something like this :
  1. #include<stdio.h>
  2. int main()
  3. {
  4. printf("%d%d",printf("Hello Daniweb"),printf("I am new here"));
  5. return 0;
  6. }

You would get an output as
I am new hereHello Daniweb1313
The inner printf's are not using a semicolon as you can see.

"printf" function returns the count of characters it has successfully output on the console and it processes from right to left internally hence first it print I am new here and then Hello Daniweb and then count of the successfully output characters of each string which in this case is 13 13.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C Forum


Views: 517 | Replies: 12
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC