I have the following code in C:
#include<stdio.h>
void main(){
printf("a" "b" "c");
}
it outputs:
abc
Can anyone explain why?
I am guessing that it is "a" "b" "c"
preprocessed as "abc"
. Am I right or Is it something else?
printf() The function printf() is used to print the message along with the values of variables. Here is the syntax of printf() in C language, printf(const char *str, ...); Here is an example of printf() in C language, Example. Live Demo
The function printf () is used to print the message along with the values of variables. printf (const char *str, ...); Welcome! The value of a : 24 The function sprintf () is also known as string print function. It do not print the string. It stores the character stream on char buffer.
As we know that, printf () is used to print the text and value on the output device, here some of the examples that we wrote to use the printf () in a better way or for an advance programming. printf ("Hello world How are you?"); Hello world How are you? To print double quote, we use \". Hello "World", How are you?
What is the output of a=50,printf ("%d%d%d", ++a, a++,--a)? The output is that the C or C++ compiler produces a number of compilation errors. The first will be that “a” has not been declared, and you will need to put an “int” in front of it.
Adjacent string literals are concatenated as part of translation phase 6.
Brief summary of phases (source: C99 standard, paraphrased)
\
are splicedAdjacent string literals are merged in compilation translation phase 6. Since "a" "b" "c"
is further treated as "abc"
string literal.
In case of you are not familiar with this term, phase 6 is somewhat between preprocessing and actual, "proper" compilation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With