- 1

Format parameter for string working even without using memory address (codes below)

#include <stdio.h> #include <string.h> int main() {    char string[10];    strcpy(string, "sample");    printf("[string] %s Address %08\n", string, string);    // Works even without using &string for %s } This code gives result even without using unary operator(&) for char array string in printf . I tried with &string in printf and it works all the same. please explain.

30th Jan 2022, 9:53 AM
Lind L Tyler
Lind L Tyler - avatar
4 Respostas
+ 2
A string variable name is a pointer for the first character. Why even use '&'? And no obviously not. Just give it a try and you'll see!
30th Jan 2022, 10:49 AM
Slick
Slick - avatar
+ 2
Yeah cause a strings variable name is a memory address to the first character.
30th Jan 2022, 9:58 AM
Slick
Slick - avatar
+ 1
Thank you
30th Jan 2022, 11:54 AM
Lind L Tyler
Lind L Tyler - avatar
0
so using '&variable' and 'variable' is technical same if the variable is a string ?? is it same for other types of variables or is it an exception ?
30th Jan 2022, 10:33 AM
Lind L Tyler
Lind L Tyler - avatar