Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

int i; Is it a declaration or a definition?

I want to know whether the statement int i; is a declaration or a definition.

It seems that if a variable is not initialized outside the function, it is declared, but inside the function it must be defined. Is this really the case?

If I write this statement multiple times outside the function, it compiles.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I write multiple statements inside the function, it does not compile.

>Solution :

c reference

If no storage-class specifier is provided, the defaults are:

  • extern for all functions
  • extern for objects at file scope
  • auto for objects at block scope

For any struct or union declared with a storage-class specifier, the storage duration (but not linkage) applies to their members, recursively.

Function declarations at block scope can use extern or none at all. Function declarations at file scope can use extern or static.

Function parameters cannot use any storage-class specifiers other than register. Note that static has special meaning in function parameters of array type.

so you should know "storage duration" and "linkage of objects"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading