how can we use a printf statement without a semicolon???
this was a question asked during an interview of a computer engineering student.

May be a printf within a printf would do the trick.Because the inner printf doesn't require the semicolon.

csurfer...howz that possible...i mean can u give the syntax plz...


william...this isnt working..i tried it out...

use this one...
#include<stdio.h>
main()
{
printf("i am an engg"),
getchar();
}

#include <stdio.h>
#define PRINT_STRING(_s) printf("%s",_s)

int main() {
    PRINT_STRING("string");
    return (0);
}

You can also try this.

#include <stdio.h>
#define PRINT_STRING(_s) printf("%s",_s)

int main() {
    PRINT_STRING("string");
    return (0);
}

You can also try this.

That's not correct, that just turns into:

#include <stdio.h>

int main() {
    printf("%s","string");
    return (0);
}

Once the preprocessor's done.

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 :

#include<stdio.h>
int main()
{
       printf("%d%d",printf("Hello Daniweb"),printf("I am new here"));
       return 0;
}

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.

how can we use a printf statement without a semicolon???
this was a question asked during an interview of a computer engineering student.

Assuming this was a job interview, I suggest you stay away from any job that asks foolish questions like this. I would not want to work for a company that want it's programmers to use tricks that make code unreadable.

Comments
Very good suggestion.
First sensible response to this thread. Exactly what I wanted to say. ;-)

how can we use a printf statement without a semicolon???
this was a question asked during an interview of a computer engineering student.

You can always put the call to printf in an if-statement, like this:

#include <stdio.h>

int main(void)
{
    if( printf("Hello World!\n") ) {}
    return 0;
}

As you can see, no semicolon is needed to invoke the printf function.

Assuming this was a job interview, I suggest you stay away from any job that asks foolish questions like this. I would not want to work for a company that want it's programmers to use tricks that make code unreadable.

Quoted for the truth.

Comments
the best of the lot
Good thinking.
This question has already been answered. Start a new discussion instead.