- 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.
4 Answers
+ 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!
+ 2
Yeah cause a strings variable name is a memory address to the first character.
+ 1
Thank you
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 ?