59.8k views
5 votes
We do not pass addresses to printf, in order to print the value of a string variable (e.g. %s).

A) True
B)False

User AndreasN
by
8.6k points

1 Answer

4 votes

Final answer:

The statement is false as we do pass the address of the first character of a string to the printf function when using the %s specifier, as strings in C are arrays which decay to pointers.

Step-by-step explanation:

When working with the printf function in the C programming language, the statement We do not pass addresses to printf, in order to print the value of a string variable is actually false. In C, a string is represented by an array of characters, and the name of the array represents the address of the first element. When we provide a string variable to printf using the %s format specifier, we are indeed passing the address of the first character of the string. This is because arrays decay to pointers when passed to functions. Hence, printf uses the address to access and print the characters of the string until it encounters the null terminator ('\0').

User Harmands
by
7.3k points