Dev C Printf Was Not Declared

Dec 28, 2010 You need to #include to use printf by the way. Also, don't worry about the speed of printf vs. That of std::cout. If there is a difference, it will be small, and not worth sacrificing the extra safety that using C strings over C. Printf and scanf functions are inbuilt library functions in C programming language which are available in C library by default. If you have C99, '%lld' will output a long long, and '%'PRId64 will. Print an int64t. Other macros in will provide similar. Specifiers for other sized integers, least and fast types, and so on. If you are using long long as an extension in a pre-C99 compiler, I'm. Reach out to all the awesome people in our software development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions. Start New Topic.

Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program.

C language uses 4 storage classes, namely:

  1. auto: This is the default storage class for all the variables declared inside a function or a block. Hence, the keyword auto is rarely used while writing programs in C language. Auto variables can be only accessed within the block/function they have been declared and not outside them (which defines their scope). Of course, these can be accessed within nested blocks within the parent block/function in which the auto variable was declared. However, they can be accessed outside their scope as well using the concept of pointers given here by pointing to the very exact memory location where the variables resides. They are assigned a garbage value by default whenever they are declared.

  2. extern: Extern storage class simply tells us that the variable is defined elsewhere and not within the same block where it is used. Basically, the value is assigned to it in a different block and this can be overwritten/changed in a different block as well. So an extern variable is nothing but a global variable initialized with a legal value where it is declared in order to be used elsewhere. It can be accessed within any function/block. Also, a normal global variable can be made extern as well by placing the ‘extern’ keyword before its declaration/definition in any function/block. This basically signifies that we are not initializing a new variable but instead we are using/accessing the global variable only. The main purpose of using extern variables is that they can be accessed between two different files which are part of a large program. For more information on how extern variables work, have a look at this link.

  3. static: This storage class is used to declare static variables which are popularly used while writing programs in C language. Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve the value of their last use in their scope. So we can say that they are initialized only once and exist till the termination of the program. Thus, no new memory is allocated because they are not re-declared. Their scope is local to the function to which they were defined. Global static variables can be accessed anywhere in the program. By default, they are assigned the value 0 by the compiler.

  4. register: This storage class declares register variables which have the same functionality as that of the auto variables. The only difference is that the compiler tries to store these variables in the register of the microprocessor if a free register is available. This makes the use of register variables to be much faster than that of the variables stored in the memory during the runtime of the program. If a free register is not available, these are then stored in the memory only. Usually few variables which are to be accessed very frequently in a program are declared with the register keyword which improves the running time of the program. An important and interesting point to be noted here is that we cannot obtain the address of a register variable using pointers.

To specify the storage class for a variable, the following syntax is to be followed:

Syntax:


Functions follow the same syntax as given above for variables. Have a look at the following C example for further clarification:

// classes
// declaring the variable which is to be made extern
intx;
voidautoStorageClass()
// writing 'int a=32;' works as well)
printf('Value of the variable 'a'
a);
printf('--------------------------------');
{
printf('Demonstrating register class');
// declaring a register variable
printf('Value of the variable 'b'
b);
printf('--------------------------------');
{
printf('Demonstrating extern class');
// telling the compiler that the variable
// defined elsewhere (above the main
externintx;
// printing the extern variables 'x'
' declared as extern: %d',
x = 2;
// printing the modified values of
printf('Modified value of the variable 'x'
x);
printf('--------------------------------');
{
printf('Declaring 'y' as static inside the loop.'
' once as 'y' is static.'
'If not, then every time the value of 'y' '
' as in the case of variable 'p');
printf('Loop started:');
for(i = 1; i < 5; i++) {
// Declaring the static variable 'y'
intp = 10;
// Incrementing the value of y and p by 1
p++;
// printing value of y at each iteration
'declared as static, in %d '
i, y);
// printing value of p at each iteration
printf('The value of non-static variable 'p', '
i, p);
}
intmain()
' Storage Classes in C');
// To demonstrate auto Storage Class
registerStorageClass();
// To demonstrate extern Storage Class
staticStorageClass();
// exiting
}
// This code is improved by RishabhPrabhu
Output:

A program to demonstrate Storage Classes in C

Demonstrating auto class

Value of the variable ‘a’ declared as auto: 32
——————————–
Demonstrating register class

Value of the variable ‘b’ declared as register: 71
——————————–
Demonstrating extern class

Value of the variable ‘x’ declared as extern: 0
Modified value of the variable ‘x’ declared as extern: 2
——————————–
Demonstrating static class

Declaring ‘y’ as static inside the loop.
But this declaration will occur only once as ‘y’ is static.
If not, then every time the value of ‘y’ will be the declared value 5 as in the case of variable ‘p’

Loop started:

The value of ‘y’, declared as static, in 1 iteration is 6
The value of non-static variable ‘p’, in 1 iteration is 11

The value of ‘y’, declared as static, in 2 iteration is 7
The value of non-static variable ‘p’, in 2 iteration is 11

The value of ‘y’, declared as static, in 3 iteration is 8
The value of non-static variable ‘p’, in 3 iteration is 11

The value of ‘y’, declared as static, in 4 iteration is 9
The value of non-static variable ‘p’, in 4 iteration is 11

Dev C Printf Was Not Declared

Loop ended:
——————————–

Storage Classes demonstrated

Dev C Printf Was Not Declared

I was trying to write a code for union and intersection of two sets but i got an error which states clrscr and exit are not declared in scope. I have included the header files but still i get this error. Can some one help me out in this?

  • 2 Contributors
  • forum5 Replies
  • 1,123 Views
  • 2 Days Discussion Span
  • commentLatest PostLatest Postby Prithvi.R.K

Recommended Answers

Post your code.

Jump to Post

Dev C Printf Was Not Declared For A

Change void main() to int main()
On line 35. if(i<3), if i is >=3 then you'll never enter that section of code. I assume that what you want to do is to keep displaying the menu until 3 is chosen. An easy way to do this would …

Jump to Post

Dev C Printf Was Not Declared To Be

All 5 Replies