1

Is the name of structure represent its address, is it true?? plzz explain

struct s{
int a;
char b;
};
struct s s1;
struct s *ptr; 

is writing 's1' represent the address of s1, means 's1' or '&s1' are same thing???

ptr=&s1;
ptr=s1; 
// which is correct??
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Abhi
  • 11
  • 1
  • 1
    *Is the name of structure represent its address?* Not really. You may be thinking of arrays. When you mention the name of an array in an expression, the value you get is a pointer to the array's first element. But that's not true for structures, or any other kind of data. (If you're a compiler writer, *any* identifier is basically a synonym for its address, but that's not normally the way we think about it when merely using an HLL like C.) – Steve Summit Jul 17 '21 at 10:29
  • Always turn on compiler warnings and you will know. – Cheatah Jul 17 '21 at 10:38

1 Answers1

0

s1 and ptr are two different types s and pointer to s respectively. so ptr=s1; won't compile. You are mixing here with the behavior of array:

int a[5];
int* ptr = a;

you can see the compiler error live

Oblivion
  • 7,176
  • 2
  • 14
  • 33