Structure Type and Variable Name

hello everyone I just wanted to know if we can declare the variable name as the name of the structure.

eg

typedef struct
{
  char c;
}t;

then in some function i can use

fun()
{
  t t;
}

Is this really so? if so, how does the compiler distinguish between them?

+3
source share
5 answers

Yes this is true. If you do this, the type of the structure will be hidden in the scope, and tonly applies to the declared variable.

+3
source

Yes, but why do you need it? If you want errors and errors to flourish in your project, go straight ahead and list the variables after the types.

+3
source

fun() { t t; }

?

, . fun() , int .

void fun(){ t t ;} .

+1

, .

t t;

, t , t.

: .

.

( ), . , t , , . , , . , , .

0

, . .

0

Source: https://habr.com/ru/post/1774223/


All Articles