0% found this document useful (0 votes)
46 views6 pages

Storage Class Keyword Memory Location Default Value Scope Life Time

The document discusses storage classes in C. It defines storage classes as used to define the storage location, scope, lifetime and default value of a variable. It mentions the auto, extern, static, and register storage classes. It distinguishes between auto and register storage classes, noting that auto variables are stored in computer memory with garbage initial values and local scope, while register variables are stored in CPU registers with garbage initial values and local scope. It provides an example of how extern can be used and notes that the storage class of a local variable declared inside a function is auto.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views6 pages

Storage Class Keyword Memory Location Default Value Scope Life Time

The document discusses storage classes in C. It defines storage classes as used to define the storage location, scope, lifetime and default value of a variable. It mentions the auto, extern, static, and register storage classes. It distinguishes between auto and register storage classes, noting that auto variables are stored in computer memory with garbage initial values and local scope, while register variables are stored in CPU registers with garbage initial values and local scope. It provides an example of how extern can be used and notes that the storage class of a local variable declared inside a function is auto.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1. Define storage class specifier.

Storage classes are used to define things like storage location (whether RAM
or REGISTER), scope, lifetime and the default value of a variable.
2. Mention different type of storage classes.
1. auto storage class
2. extern storage class
3. static storage class
4. register storage class

3. Distinguish between auto and register

Storage Memory Default


Class Keyword Location Value Scope Life Time

Automati auto Computer Garbage Local to Till the control


c Memory Value the block remains within the
(RAM) in which block in which
the variable is defined
variable
has
defined

Register register CPU Garbage Local to Till the control


Register Value the block remains within the
in which block in which
the variable is defined
variable
has
defined

4. What is meant by extern? Give an example.


The default storage class of all global variables (variables declared outside
function) is external storage class.
Example
#include<stdio.h>
#include<conio.h>
int i;    //By default it is extern variable
int main()
{
     printf("%d",i);
     return 0;
}

5. What is storage class for variable A in below code?Justify.


int main()
{
int A;
A = 10;
printf("%d", A);
return 0;
}
The default storage class of all local variables (variables declared inside
block or function) is auto storage class.

6. What will the SWAP macro in the following program be expanded to on


preprocessing? will the code compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
int x=10, y=20;
SWAP(x, y, int);
printf("%d %d\n", x, y);
return 0;
}

7. How are preprocessor directives written in C?


C program is compiled in a compiler, source code is processed by a program
called preprocessor. This process is called preprocessing. Commands used
in preprocessor are called preprocessor directives and they begin with “#”
symbol.
8. How can you avoid including a header more than once?
One easy technique to avoid multiple inclusions of the same header is to use the #ifndef
and #define preprocessor directives. When you create a header for your program, you
can #define a symbolic name that is unique to that header.

9. How to pragma directive works?


These directives helps us to specify the functions that are needed to run
before program startup( before the control passes to main()) and just before
program exit (just before the control returns from main()).
10.Compare the pragma and conditional directive.
pragma directive conditional directive
Syntax:  #pragma #ifdef, #endif, #if,
#else, #ifndef
Definitio #Pragma is used to call a function before Set of commands are
n and after main function in a C program. included or excluded in
source program before
compilation with
respect to the
condition. 

11.Examine the six pragma directives.


#pragma startup, #pragma exit, #pragma warn, #pragma GCC dependency,
#pragma GCC system_header and #pragma GCC poison
12.Write the syntax of pragma directive.

#pragma token_name

13.Is there any difference that arises if double quotes , instead of angular
brackets are used for including the standard header file?
When include file in <> then it searches the specified file system directory.Ex.
#include<stdio.h>It will search stdio. h file in system directory.
When including file in “” Then it search this specified file in currently working directory.

14.Identify the use of pragma directive in c.


The preprocessor directive #pragma is used to provide the additional
information to the compiler in C language.

15.List out the seven conditional directives in c.


#if, #ifdef, #ifndef, #else, #elif, #endif, and defined

16.What is the use of #if directive?


“#ifdef” directive checks whether particular macro is defined or not. If it is
defined, “If” clause statements are included in source file.
Otherwise, “else” clause statements are included in source file for
compilation and execution.

17.Write a note on define macro.


This macro defines constant value and can be any of the basic data types.
There are two types of macros:
(i) Object-like Macros
(ii) Function-like Macros

18.Evaluate the advantages of a macro over a function.


When writing macros for functions, they saves a lot of time that is spent by
the compiler for invoking / calling the functions. Hence, The advantage of
a macro over an actual function, is speed. No time is taken up in passing
control to a new function, because control never leaves the home function
19.Develop an example for conditional compilation.
#include <stdio.h>
#define X 45.25
int main()
{
#if !X
 printf("Hello");
#else
 printf("World");
#endif
return 0;
}
Output:
main.c: In function ‘main’:
main.c:2:11: error: floating constant in preprocessor expression
#define X 45.25
^
main.c:5:10: note: in expansion of macro ‘X’
#if !
20.What does #undef, #pragma indicate in c?
The #pragma preprocessor directive is used to provide additional
information to the compiler. The #pragma directive is used by the compiler
to offer machine or operating-system feature

PART C
1. Write any two common macro pitfalls with example program.
(i) Misnesting
When a macro is called with arguments, the arguments are substituted into the
macro body and the result is checked, together with the rest of the input file, for
more macro calls. It is possible to piece together a macro call coming partially
from the macro body and partially from the arguments. For example,
#define twice(x) (2*(x))
#define call_with_1(x) x(1)
call_with_1 (twice)
==> twice(1)
==> (2*(1))

Macro definitions do not have to have balanced parentheses. By writing an unbalanced


open parenthesis in a macro body, it is possible to create a macro call that begins inside
the macro body but ends outside of it. For example,
#define strange(file) fprintf (file, "%s %d",

strange(stderr) p, 35)
==> fprintf (stderr, "%s %d", p, 35)

The ability to piece together a macro call can be useful, but the use of
unbalanced open parentheses in a macro body is just confusing, and should be
avoided.
(ii) Operator Precedence Problems
You may have noticed that in most of the macro definition examples shown above, each
occurrence of a macro argument name had parentheses around it. In addition, another
pair of parentheses usually surround the entire macro definition. Here is why it is best to
write macros that way.
Suppose you define a macro as follows,
#define ceil_div(x, y) (x + y - 1) / y
whose purpose is to divide, rounding up. (One use for this operation is to compute how
many int objects are needed to hold a certain number of char objects.) Then suppose it is
used as follows:
a = ceil_div (b & c, sizeof (int));
==> a = (b & c + sizeof (int) - 1) / sizeof (int);
his does not do what is intended. The operator-precedence rules of C make it
equivalent to this:
a = (b & (c + sizeof (int) - 1)) / sizeof (int);

2. Write preprocessor directives code in C for roots of a quadratic equation.


3. Develop a C Program based on conditional directive to display the Distinction, First class and
Second class based on the student mark is above 70, between 60 to 70 and between 40 to 60
respectively otherwise Fail.
4. Summarize of storage classes with respect to various parameters storage location, initial
value, lifetime and linkage

You might also like