blog banner
 

1. Explain C storage classes

A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify. We have four different storage classes in a C program −

    1. auto
    2. register
    3. static
    4. extern

 

2. Explain Extern keyword in C ?

extern defines a global variable that is visable to ALL object modules. When you use 'extern' keyword while declaring a variable, then compiler will understand this variable is declared and initialized in some other file or module.

Extern variables cannot be initalized as the moment you declare a variable as extern, compiler will search for the variable name at a storage location that has been previously defined and will use that..

File1.c File2.c

extern int count;
 
write()
{

printf("count is %d\n", count);

}


int count=5;
 
main()
{

write();

}

Count in 'source 1' will have a value of 5. If source 1 changes the value of count - source 2 will see the new value.

The compile command will look something like.

gcc source1.c source2.c -o program
 

3. Explain the static keyword in C

static has different meanings in different contexts.

  • When specified on a function declaration, it makes the function local to the file.
  • When specified with a variable inside a function, it allows the vairable to retain its value between calls to the function.

Static Functions

By default all functions are implicitly declared as extern, which means they're visible across translation units. But when we use static it restricts visibility of the function to the translation unit in which it's defined.

In C, functions are global by default. The “static” keyword before a function name makes it static. Unlike global functions(extern) in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files.

For example, if we store following program in one file file1.c

/* Inside file1.c */
static void fun1(void)
{

puts("fun1 called");

}

And store following program in another file file2.c

/* Iinside file2.c */
int main(void)
{

fun1();
getchar();
return 0;

}

Now, if we compile the above code with command “gcc file2.c file1.c”, we get the error “undefined reference to 'fun1’” . This is because fun1() is declared static in file1.c and cannot be used in file2.c.
 

Static Variables :

When a variables is declared as static with in a function, it allows the vairable to retain its value between different calls to the function.

The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope of the function (i.e. between different calls to the function). Therefore, making local variables static allows them to maintain their values between function calls.

The static modifier may also be applied to global variables. When this is done, it causes that variable's scope to be restricted to the file in which it is declared.

#include<stdio.h>

 

/* function declaration */

void func(void);

static int count = 5; /* global variable */

main() {

while(count--) {

func();

}

return 0;

}

/* function definition */
void func( void ) {

static int i = 5; /* local static variable */
i++;

printf("i is %d and count is %d\n", i, count);

}

 

Output : 

i is 6 and count is 4
i is 7 and count is 3
i is 8 and count is 2
i is 9 and count is 1
i is 10 and count is 0
 

4. Explain the auto keyword?

The auto storage class is the default storage class for all local variables.

{

int Count;
auto int Month;

}

The example above defines two variables with the same storage class. auto can only be used within functions, i.e. local variables.
 

5. Explain the register keyword

register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and cant have the unary '&' operator applied to it (as it does not have a memory location).


{

register int Miles;

}


Register should only be used for variables that require quick access - such as counters. It should also be noted that defining 'register' goes not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register - depending on hardware and implimentation restrictions.
 

6. The const Keyword in C

The const keyword is used to create a read only variable. Once initialised, the value of the variable cannot be changed but can be used just like any other variable.
const syntax

main()
{

const float pi = 3.14;

}

properties :

  • C Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined.
  • Constants refer to fixed values. They are also called as literals
  • Constants may be belonging to any of the data type.

 

7. What is volatile keyword?

The volatile keyword is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler.
Objects declared as volatile are omitted from optimization because their values can be changed by code outside the scope of current code at any time.

 

8. Can a variable be both const and volatile?

yes, the const means that the variable cannot be assigned a new value. The value can be changed by other code or pointer. For example the following program works fine.

int main(void)
{

const volatile int local = 10;
int *ptr = (int*) &local;
printf("Initial value of local : %d \n", local);
*ptr = 100;
printf("Modified value of local: %d \n", local);
return 0;

}

 

9. What is c preprocessor ?

The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.

All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column.

The C preprocessor modifies a source file before handing it over to the compiler, allowing conditional compilation with #ifdef, defining constants with #define, including header files with #include<stdio.h>, and using builtin macros such as __FILE__.

Properties :

    • Before a 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.

Types : 

Preprocessor Syntax Description
Macro #define This macro defines constant value and can be any of the basic data types.
Header file inclusion #include<stdio.h> <file_name> The source code of the file “file_name” is included in the main program at the specified place
Conditional compilation #ifdef, #endif, #if, #else, #ifndef Set of commands are included or excluded in source program before compilation with respect to the condition
Other directives #undef, #pragma
#undef is used to undefine a defined macro variable.
#Pragma is used to call a function before and after main function in a C program

 

10. What is Macros in C? What are the advantages of using a Macro?

A macro is a name given to a block of C statements as a pre-processor directive. Being a pre-processor, the block of code is communicated to the compiler before entering into the actual coding (main () function). A macro is defined with the preprocessor directive, #define.

Macros are generally used to define constant values that are being used repeatedly in program. Macros can even accept arguments and such macros are known as function-like macros. It can be useful if tokens are concatenated into code to simplify some complex declarations. Macros provide text replacement functionality at pre-processing time.

Here is an example of a simple macro :

#define MAX_SIZE 10

The above macro (MAX_SIZE) has a value of 10.

Advantages

- The speed of the execution of the program is the major advantage of using a macro.

- It saves a lot of time that is spent by the compiler for invoking / calling the functions.

- It reduces the length of the program.

Now let’s see an example through which we will confirm that macros are replaced by their values at pre-processing time. Here is a C program :

#include<stdio.h>

#define MAX_SIZE 10

int main(void)
{

int size = 0;
size = size + MAX_SIZE;

printf("\n The value of size is [%d]\n",size);

return 0;

}

Output :

The value of size is 10

 

11. How memory is allocated when a variable is declared in C Programming?

Global variables, static variables and program instructions get their memory in permanent storage area whereas local variables are stored in area called Stack. The memory space between these two region is known as Heap area. This region is used for dynamic memory allocation during execution of the program. Pointers are also stored in heap area. The size of heap keep changing.


 

12. What is Dynamic memory allocation in C programming ?

Generally for most variables memory is allocated during compilation time. The process of allocating memory during program execution (run time) is called dynamic memory allocation.

C language offers 4 dynamic memory allocation functions. They are,

Function Syntax Usage
malloc () malloc (number *sizeof(int)); Allocates requested size of bytes and returns a pointer first byte of allocated space
calloc () calloc (number, sizeof(int)); Allocates space for an array elements, initializes to zero and then returns a pointer to memory
realloc () realloc (pointer_name, number * sizeof(int)); Change the size of previously allocated space
free () free (pointer_name); dellocate the previously allocated space

 
13. What is the use of malloc() ?

The name malloc stands for "memory allocation". The function malloc() reserves a block of memory of specified size and return a pointer of type void which can be casted into pointer of any form.

Properties :

  • malloc () function is used to allocate space in memory during the execution of the program.
  • malloc () does not initialize the memory allocated during execution. It carries garbage value.
  • malloc () function returns null pointer if it couldn’t able to allocate requested amount of memory.

Example :

ptr=(int*)malloc(100*sizeof(int));

This statement will allocate either 200 or 400 according to size of int 2 or 4 bytes respectively and the pointer points to the address of first byte of memory.
 

14. What is the use of calloc()?

The name calloc stands for "contiguous allocation". The only difference between malloc() and calloc() is that, malloc() allocates single block of memory whereas calloc() allocates multiple blocks of memory each of same size and sets all bytes to zero.

Difference with malloc

calloc () function is also like malloc () function. But calloc () initializes the allocated memory to zero. But, malloc() doesn’t.

Example :

ptr=(float*)calloc(25,sizeof(float));
This statement allocates contiguous space in memory for an array of 25 elements each of size of float, i.e, 4 bytes.
 

15. What is the use of realloc() ?

If the previously allocated memory is insufficient or more than sufficient. Then, you can change memory size previously allocated using realloc().

Properties :

  • realloc () function modifies the allocated memory size by malloc () and calloc () functions to new size.
  • If enough space doesn’t exist in memory of current block to extend, new block is allocated for the full size of reallocation, then copies the existing data to new block and then frees the old block.

 

16. What is the use of free()?

Dynamically allocated memory with either calloc() or malloc() does not get return on its own. The programmer must use free() explicitly to release space.
 

17. Write an example to illustrate the use of realloc().

 

#include<stdio.h>

#include<stdlib.h>
int main(){

int *ptr,i,n1,n2;
printf("Enter size of array: ");
scanf("%d",&n1);


ptr=(int*)malloc(n1*sizeof(int));

printf("Address of previously allocated memory: ");
for(i=0;i<n1;++i)

printf("%u\t",ptr+i);


printf("\nEnter new size of array: ");
scanf("%d",&n2);


ptr=realloc(ptr,n2);
for(i=0;i<n2;++i)

printf("%u\t",ptr+i);


return 0;

}
 

18. Write a program to explain the use of malloc() and free() ?

#include<stdio.h>
#include<stdlib.h>
int main(){

int n,i,*ptr,sum=0;
printf("Enter number of elements: ");
scanf("%d",&n);


ptr=(int*)malloc(n*sizeof(int)); //memory allocated using malloc
if(ptr==NULL)
{

printf("Error! memory not allocated.");
exit(0);

}
printf("Enter elements of array: ");
for(i=0;i<n;++i)
{

scanf("%d",ptr+i);
sum+=*(ptr+i);

}
printf("Sum=%d",sum);
free(ptr);
return 0;

}
 

19. Write a c programme to explain the use of calloc() and free() ?

#include<stdio.h>
#include<stdlib.h>
int main(){

int n,i,*ptr,sum=0;
printf("Enter number of elements: ");
scanf("%d",&n);


ptr=(int*)calloc(n,sizeof(int));
if(ptr==NULL)
{

printf("Error! memory not allocated.");
exit(0);

}
printf("Enter elements of array: ");
for(i=0;i<n;++i)
{

scanf("%d",ptr+i);
sum+=*(ptr+i);

}

printf("Sum=%d",sum);
free(ptr);
return 0;

}
 

19. What are the differences between STATIC MEMORY ALLOCATION and DYNAMIC MEMORY ALLOCATION in C Programming ?

Static memory allocation Dynamic memory allocation
In static memory allocation, memory is allocated while writing the C program. Actually, user requested memory will be allocated at compile time. In dynamic memory allocation, memory is allocated while executing the program. That means at run time.
Memory size can’t be modified while execution.
Example: array
Memory size can be modified while execution.
Example: Linked list

 

20. What are the difference beweent calloc() and malloc() ?

malloc() calloc()
It allocates only single block of requested memory It allocates multiple blocks of requested memory
int *ptr;ptr = malloc( 20 * sizeof(int) );For the above, 20*4 bytes of memory only allocated in one block.
Total = 80 bytes
int *ptr;Ptr = calloc( 20, 20 * sizeof(int) );For the above, 20 blocks of memory will be created and each contains 20*4 bytes of memory.
Total = 1600 bytes
malloc () doesn’t initializes the allocated memory. It contains garbage values calloc () initializes the allocated memory to zero
type cast must be done since this function returns void pointer int *ptr;ptr = (int*)malloc(sizeof(int)*20 ); Same as malloc () function int *ptr;ptr = (int*)calloc( 20, 20 * sizeof(int) );

 

21. In C programming, how do you insert quote characters (‘ and “) into the output screen?

This is a common problem for beginners because quotes are normally part of a printf statement. To insert the quote character as part of the output, use the format specifiers \’ (for single quote), and \” (for double quote).

 

22. What is the use of a ‘\0' character?

It is referred to as a terminating null character, and is used primarily to show the end of a string value.


23. What are compound statements?

Compound statements are made up of two or more program statements that are executed together. This usually occurs while handling conditions wherein a series of statements are executed when a TRUE or FALSE is evaluated. Compound statements can also be executed within a loop. Curly brackets { } are placed before and after compound statements.

 

24. How do you generate random numbers in C?

Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

 

25. What does the format %10.2 mean when included in a printf statement?

This format is used for two things: to set the number of spaces allotted for the output number and to set the number of decimal places. The number before the decimal point is for the allotted space, in this case it would allot 10 spaces for the output number. If the number of space occupied by the output number is less than 10, addition space characters will be inserted before the actual output number. The number after the decimal point sets the number of decimal places, in this case, it’s 2 decimal spaces.


26. What are the different file extensions involved when programming in C?

Source codes in C are saved with .C file extension. Header files or library files have the .H file extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and an executable .EXE file.

 

27. What are reserved words?

Reserved words are words that are part of the standard C language library. This means that reserved words have special meaning and therefore cannot be used for purposes other than what it is originally intended for. Examples of reserved words are int, void, and return.
 

28. What is infinite loop?

A loop running continuously for indefinite number of times is called infinite loop.


Infinite For Loop:

 for(;;){

//code to be executed

 }
 

29. What is pointer to pointer in C?

A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.

A variable that is a pointer to a pointer must be declared as such. This is done by placing an additional asterisk in front of its name. For example, the following declaration declares a pointer to a pointer of type int −

int **var;

When a target value is indirectly pointed to by a pointer to a pointer, accessing that value requires that the asterisk operator be applied twice, as is shown below in the example −

#include<stdio.h>

int main () {

int var;
int *ptr;
int **pptr;

 

var = 3000;

 

/* take the address of var */
ptr = &var;

 

/* take the address of ptr using address of operator & */
pptr = &ptr;

 

/* take the value using pptr */
printf("Value of var = %d\n", var );
printf("Value available at *ptr = %d\n", *ptr );
printf("Value available at **pptr = %d\n", **pptr);

 

return 0;

}

When the above code is compiled and executed, it produces the following result −

Value of var = 3000
Value available at *ptr = 3000
Value available at **pptr = 3000
 

30. What is recursion in C programming?

Calling the same function, inside function is known as recursion.

For example:

void function1(){

function1();

}

Many Programs in C using recursion is done here
 

31. What is the difference between local variable and global variable in C?

Local variable: A variable which is declared inside a function or block is known as local variable. The life time of this type of variable is as long as the control stays in that function within which the variable is declared. Once the control goes out of that function, the variable losts its value and declaration. This variable can not be used or referred from outside that function.


Global variable: A variable which is declared outside function or block is known as global variable. Typically , we declare a global variable before that start of main() function, just after including standard files. By doing this , these variable life time spans entire program execution and can be used or referred from anywhere.
 

32. What is header files in C ?

A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.

 

You request to use a header file in your program by including it with the C preprocessing directive #include<stdio.h>, like you have seen inclusion of stdio.h header file, which comes along with your compiler.

 

Including a header file is equal to copying the content of the header file but we do not do it because it will be error-prone and it is not a good idea to copy the content of a header file in the source files, especially if we have multiple source files in a program.
 

33. What is the use of sizeof() function in C?


The sizeof operator returns the size in bytes of its operand. Operand may be a variable or data type.
Properties :
  • sizeof operator is used to calcualte the size of data type or variables.sizeof operator can be nested.sizeof operator will return the size in integer format.
  • sizeof operator syntax looks more like a function but it is considered as an operator in c programming

 

Examples

sizeof(int)

OR,

int ivar = 100;

sizeof(ivar)

Both will retur 2 or 4 depending on the compiler

 

35. What is l-value?

l-value or location value refers to an expression that can be used on left side of assignment operator. For example in expression “a = 3″, a is l-value and 3 is r-value.
l-values are of two types:

  1. “nonmodifiable l-value” represent a l-value that can not be modified. const variables are “nonmodifiable l-value”.
  2. “modifiable l-value” represent a l-value that can be modified.

 

36. Differentiate Source Codes from Object Codes

Source codes are codes that were written by the programmer. It is made up of the commands and other English-like keywords that are supposed to instruct the computer what to do. However, computers would not be able to understand source codes. Therefore, source codes are compiled using a compiler. The resulting outputs are object codes, which are in a format that can be understood by the computer processor. In C programming, source codes are saved with the file extension .C, while object codes are saved with the file extension .OBJ
 

37. What is syntax error?

Syntax errors are associated with mistakes in the use of a programming language. It maybe a command that was misspelled or a command that must was entered in lowercase mode but was instead entered with an upper case character. A misplaced symbol, or lack of symbol, somewhere within a line of code can also lead to syntax error.
 

38. What are variables and it what way is it different from constants?

Variables and constants may at first look similar in a sense that both are identifiers made up of one character or more characters (letters, numbers and a few allowable symbols). Both will also hold a particular value. Values held by a variable can be altered throughout the program, and can be used in most operations and computations. Constants are given values at one time only, placed at the beginning of a program. This value is not altered in the program. For example, you can assigned a constant named PI and give it a value 3.1415 . You can then use it as PI in the program, instead of having to write 3.1415 each time you need it.
 

39. Describe the order of precedence with regards to operators in C.

Order of precedence determines which operation must first take place in an operation statement or conditional statement. On the top most level of precedence are the unary operators !, +, – and &. It is followed by the regular mathematical operators (*, / and modulus % first, followed by + and -). Next in line are the relational operators <, <=, >= and >. This is then followed by the two equality operators == and !=. The logical operators && and || are next evaluated. On the last level is the assignment operator =.

 

40. What are actual arguments?

When you create and use functions that need to perform an action on some given values, you need to pass these given values to that function. The values that are being passed into the called function are referred to as actual arguments.

 

41. What is a newline escape sequence?

A newline escape sequence is represented by the n character. This is used to insert a new line when displaying data in the output screen. More spaces can be added by inserting more n characters. For example, nn would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.

 

42. What are run-time errors?

These are errors that occur while the program is being executed. One common instance wherein run-time errors can happen is when you are trying to divide a number by zero. When run-time errors occur, program execution will pause, showing which program line caused the error.

 

43. What are formal parameters?

In using functions in a C program, formal parameters contain the values that were passed by the calling function. The values are substituted in these formal parameters and used in whatever operations as indicated within the main body of the called function.

 

44. What are control structures?

Control structures take charge at which instructions are to be performed in a program. This means that program flow may not necessarily move from one statement to the next one, but rather some alternative portions may need to be pass into or bypassed from, depending on the outcome of the conditional statements.

 

45. What is dynamic data structure?

Dynamic data structure provides a means for storing data more efficiently into memory. Using dynamic memory allocation, your program will access memory spaces as needed. This is in contrast to static data structure, wherein the programmer has to indicate a fix number of memory space to be used in the program.

 

46. What is inline function in C?

The intent of the inline specifier is to serve as a hint for the compiler to perform optimizations, such as function inlining, which require the definition of a function to be visible at the call site. The compilers can (and usually do) ignore presence or absence of the inline specifier for the purpose of optimization.


If the compiler performs function inlining, it replaces a call of that function with its body, avoiding the overhead of a function call (placing data on stack and retrieving the result), which may result in a larger executable as the code for the function has to be repeated multiple times. The result is similar to function-like macros, except that identifiers and macros used in the function refer to the definitions visible at the point of definition, not at the point of call.


Regardless of whether inlining takes place, the following semantics of inline functions are guaranteed:

  • Any function with internal linkage may be declared static inline with no other restrictions.
  • A non-static inline function cannot define a non-const function-local static and cannot refer to a file-scope static.

static int x;
inline void f(void)
{

static int n = 1; // error: non-const static in a non-static inline function
int k = x; // error: non-static inline function accesses a static variable

}

If a non-static function is declared inline, then it must be defined in the same translation unit. The inline definition that does not use extern is not externally visible and does not prevent other translation units from defining the same function. This makes the inline keyword an alternative to static for defining functions inside header files, which may be included in multiple translation units of the same program.
 

47. What is conditional MACRO ? Or, How can we check if a macro is already declared or not ?

Conditional macros are very useful to apply conditions. Code snippets are guarded with a condition checking if a certain macro is defined or not. They are very helpful in large project having code segregated as per releases of project. If some part of code needs to be executed for release 1 of project and some other part of code needs to be executed for release 2, then it can be easily achieved through conditional macros.

So, Using ifdef we can check whether a macro is delivered 

#define MAX 50

int main()

{

#ifdef MAX

..
.. int arr[MAX];
..

#else

..
.. int arr[50];
..

#endif

}
 

48. How to re define a value of MACRO ? Or, How will you override an existing macro in C? Or, How to undefine or re define a MACRO?

The process for redefining a macro is 

Step 1: Undefine the MACRO

Step 2: Again define the MACRO

Undefining a Macro :

If a macro ceases to be useful, it may be undefined with the ‘#undef’ directive. ‘#undef’ takes a single argument, the name of the macro to undefine. You use the bare macro name, even if the macro is function-like. It is an error if anything appears on the line after the macro name. ‘#undef’ has no effect if the name is not a macro.

#define FOO 4
x = FOO; ==> x = 4;


#undef FOO
x = FOO; ==> x = FOO;


Once a macro has been undefined, that identifier may be redefined as a macro by a subsequent ‘#define’ directive.

Re defining a MACRO

#define FOO 4

#undef FOO

#define FOO 6
 

49. What is the use of “goto” statement?

The goto statement is used to alter the normal sequence of program execution by transferring control to some other part of the program unconditionally. A goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function.

The syntax for a goto statement in C is as follows −

goto label;
..
.
label: statement;

Here label can be any plain text except C keyword and it can be set anywhere in the C program above or below to goto statement.

Example

#include<stdio.h>

int main () {

/* local variable definition */
int a = 10;

/* do loop execution */
LOOP:do {

if( a == 13) {

/* skip the iteration */
a = a + 1;
goto LOOP;

}

printf("value of a: %d\n", a);
a++;

}while( a < 15 );

return 0;

}

Output:

value of a: 10
value of a: 11
value of a: 12
value of a: 14
value of a: 15
 

50. What will happen if break statement is not used in switch case in C? Or, What is Fall through in C?

Break statement is used in switch statement for terminating any case condition. If you do not put break statement after any case, then satisfying the case condition it will now proceed to the next case statement and will continue moving to next case statement until it finds a break statement in same switch block. This situation known as fall through. And in case of default statement, break is not the compulsory statement. It is optional.
 

51. Why is default statement used in switch case in C?

When no other cases matches then the actions mentioned and default case will be triggered.
 

52. What is modifiers in C? Or, What is datatype modifiers in C?

In c language Data Type Modifiers are keywords used to change the properties of current properties of data type. Data type modifiers are classified into following types.

  1. long
  2. short
  3. unsigned
  4. signed

Modifiers are prefixed with basic data types to modify (either increase or decrease) the amount of storage space allocated to a variable.

For example, storage space for int data type is 4 byte for 32 bit processor. We can increase the range by using long int which is 8 byte. We can decrease the range by using short int which is 2 byte.
 

53. Explain The different Type of Modifiers ?

Signed Type Modifier:

All data types are “signed” by default. Signed Data Modifier implies that the data type variable can store positive values as well as negative values.

For example, if we need to declare a variable to store temperature, it can be negative as well as positive.

signed int temperature;

Or

int temperature;

Unsigned Type Modifier:

If we need to change the data type so that it can only store only store positive values, “unsigned” data modifier is used.

For example, if we need to declare a variable to store the salary of an employee as explained above, we will use “Unsigned” Data Qualifier here.

unsigned int salary;

Long Type Modifier:

Sometimes while coding a program, we need to increase the Storage Capacity of a variable so that it can store values higher than its maximum limit which is there as default. In such situations or programs, we need to make use of the “long” data type qualifier. “long” type modifier doubles the “length” of the data type when used along with it.

For example, if we need to store the “annual turnover” of a company in a variable, we will make us of this type qualifier.

long int turnover;

This variable will take 4 Bytes in memory.

Short Type Modifier:

A “short” type modifier does just the opposite of “long”. If one is not expecting to see high range values in a program and the values are both positive & negative.

For example, if we need to store the “age” of a student in a variable, we will make use of this type qualifier as we are aware that this value is not going to be very high.

short int age;

This variable will consume only 1 Byte in memory.
 

54. What is the Declaration and Definition in C program ?

Declaration of Function :

Whenever we write function after the main function, compiler will through the error since it does not have any idea about the function at the time of calling function. If we provide prototype declaration of function then we compiler will not look for the definition.

int sum(int,int);

Declaring Variable

Whenever we write declaration statement then memory will not be allocated for the variable. Variable declaration will randomly specify the memory location.

int ivar;

Defining A function :

A function definition specifies the name of the function, the types and number of parameters it expects to receive, and its return type. A function definition also includes a function body with the declarations of its local variables, and the statements that determine what the function does.

int sum(int n1,int n2)
{

return(n1+n2);

}
 

Defining a variable :

We define a variable, when we initialize and assign a value to it. When we define a variable it allocates a value to the memory location of the corresponding variable.

 

55. What is the Difference between Declaration of a variable and Definition of a variable in C program ?


  

Admin Team


0 Respond



Written
Exam Questions
BLOG Posts
For study materials
Job Walk-In
Updates across India
Interview round
Questions
Interview or procedure
Experiences
Files
For study materials
Please LIKE our page to Get regular JOB WALK-IN UPDATES across India and STUDY MATERIALS on facebook news feed.