Aishwarya Rane
Aishwarya Rane

Reputation: 33

How many declaration of variables can be done in a C program?

In a C program,we usually declare less number of variables. Whether is it possible to declare 'n' number of variables? for ex: int a,int b,int c ....... Or whether compiler gives me an error?

Is there a maximum limit for the declarations of variables?

Upvotes: 0

Views: 2709

Answers (2)

chux
chux

Reputation: 154280

A compiler is not obliged to have an upper limit. But if it has a limit, it can only be so small.

C does define minimal maximum limits.

See C11 5.2.4.1 Translation limits

Examples:

4095 external identifiers in one translation unit
511 identifiers with block scope declared in one block
127 parameters in one function definition
1023 members in a single structure or union

Upvotes: 4

Evil
Evil

Reputation: 480

There is no explicit limit for number of variables. Moreover this is connected to specific compiler, but there are indications about what minimal number of scopes, local variables and identifiers length must be supported to call it standard conformant.

The limit itself is not anyhow connected to memory available at runtime.

Any limit (constraint) on the source code must be explicitly given in compiler documentation (this is statement taken from the C standard indication, paragraph limits).

Upvotes: 1

Related Questions