Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

structure type and variable name

Tags:

c

hi all i just wanted to know whether we can declare variable name as structure name.

for example

typedef struct
{
  char c;
}t;

then in some function can i use

fun()
{
  t t;
}

is this valid? if so then how compiler differentiate between them?

like image 281
user277773 Avatar asked Feb 22 '26 01:02

user277773


2 Answers

Yes, it is valid. If you do that, then the structure type is hidden in the enclosing scope and t refers only to the declared variable.

like image 114
casablanca Avatar answered Feb 23 '26 17:02

casablanca


Yes, but why would you want to? If you want bugs and errors to thrive in your project, then go right ahead and name variables after types.

like image 44
Alexander Rafferty Avatar answered Feb 23 '26 16:02

Alexander Rafferty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!