What is C language?

The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages.

What is the difference between “printf(…)” and “sprintf(…)”?

Ans.  sprintf(…) writes data to the character array whereas printf(…) writes data to the standardoutput device.

How to reduce a final size of executable?

Ans.  Size of the final executable can be reduced using dynamic linking for libraries.

What does static variable mean?

Ans. There are 3 main uses for the static.

1. If you declare within a function:

It retains the value between function calls

2.If it is declared for a function name:

By default function is extern..so it will be visible from other files if the function declaration is as static..it is invisible for the outer files

3. Static for global variables:

By default we can use the global variables from outside files If it is static global..that variable is limited to with in the file.

What are the differences between malloc() and calloc()?

Ans. There are 2 differences.

First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable).

Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

What is the difference between strings and character arrays?

Ans.  A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword.

Which bitwise operator is suitable for checking whether a particular bit is on or off?

Ans.  The bitwise AND operator.

  When is a switch statement better than multiple if statements?

Ans.  A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

What is static function?

A static function is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable. If the function or variable is visible outside of the current source file, it is said to have global, or external, scope. If the function or variable is not visible outside of the current source file, it is said to have local, or static, scope.

What is a pointer variable?

Ans.  A pointer variable is a variable that may contain the address of another variable or any valid address in the memory.

What is a pointer value and address?

Ans.  A pointer value is a data object that refers to a memory location. Each memory location is numbered in the memory. The number attached to a memory location is called the address of the location.

What are the characteristics of arrays in C?

An array holds elements that have same data type.

-Array elements are stored in subsequent memory locations.

-Two-dimensional array elements are stored row by row in subsequent memory locations.

-Array name represents the address of the starting element.

-Array size should be mentioned in the declaration. Array size must be a constant expression and not a variable.

  In C, why is the void pointer useful?

Ans.  When would you use it? The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

  • What is a pointer on pointer?

It’s a pointer variable that can hold the address of another pointer variable.

Eg: int x = 5, *p=&x, **q=&p;

Therefore ‘x’ can be accessed by **q.

  • What is a static variable?

A static local variable retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice.

  • What is a NULL pointer?

A pointer pointing to nothing is called Null Pointer. Eg: char *p=NULL;

  • What is a nested structure?

A structure containing an element of another structure as its member is referred so.

  • Explain modular programming.

Dividing the program into subprograms (modules/function) to achieve the given task is a modular approach. More generic functions definition gives the ability to re-use the functions, such as built-in library functions.

  • What is a token?

C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

  • What is a preprocessor?

The preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

  • What are command line arguments?

The arguments which we pass to the main() function while executing the program are called command-line arguments.

  • What is the meaning of base address of the array?

The starting address of the array is called the base address of the array.

  • What are bit fields?

We can create integer structure members of differing sizes apart from non-standard sizes using bit fields. Such structure size is automatically adjusted with the multiple integer size of the machine.

  • What is a static function?

A function’s definition prefixed with a static keyword is called a static function.

  • What is a NULL statement?

A null statement is no executable statement such as ; (semicolon).

Eg: int count = 0;

while( ++count<=10 ) ;   Above does nothing 10 times.

  • What is a pointer to a function?.

A pointer holding the reference of the function is called a pointer to a function.

  • Define an array.

The array is a collection of similar data items under a common name.

  • Explain about ‘stdin’.

stdin in a pointer variable which is by default opened for the standard input device.

  • Define a structure.

A structure can be defined as a collection of heterogeneous data items.

  • What is typecasting?

Typecasting is a way to convert a variable/constant from one type to another type.

  • What is recursion?

Function calling itself is called recursion.

  • What is a string length?

It is the count of characters excluding the ‘\0’ character.

  • What is a constant?

A value that cannot be modified is called so. Such variables are qualified with the keyword const.

  • What is the output file generated by the linker.

The linker generates the executable file.

  • What is the maximum length of an identifier?

Ideally, it is 32 characters and also implementation-dependent.

  • What is the default function call method?

By default, the functions are called by value.

Functions must and should be declared. Comment on this.

The function declaration is optional if the same is invoked after its definition.

  • When the macros gets expanded?

At the time of preprocessing.

  • What is a constant pointer?

A pointer is not allowed to be altered to hold another address after it is holding one.

  • What is the default value of local and global variables?

Local variables get garbage value and global variables get a value 0 by default.

  • What are valid operations on pointers?

The only two permitted operations on pointers are

Comparision ii) Addition/Substraction (excluding void pointers)

  • What is an infinite loop?

A loop executing repeatedly as the loop-expression always evaluates to true such as

while(0 == 0) {


  • What is the advantage of declaring void pointers?

When we do not know what type of memory address the pointer variable is going to hold, then we declare a void pointer for such.

  • Describe the file opening mode “w+”.

Opens a file both for reading and writing. If a file is not existing it creates one, else if the file is existing it will be overwritten.


  1. What is keyword auto for?

By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables.

void f() {

int i;

auto int j;


NOTE − A global variable can’t be an automatic variable.

  • When to user -> (arrow) operator.

If the structure/union variable is a pointer variable, to access structure/union elements the arrow operator is used.

  • What is the purpose of built-in stricmp() function.

It compares two strings by ignoring the case.

  • Explain the purpose of the function sprintf().

Prints the formatted output onto the character array.

  • What is the purpose of the keyword typedef?

It is used to alias the existing type. Also used to simplify the complex declaration of the type.

  • Explain the use of %i format specifier w.r.t scanf().

Can be used to input integers in all the supported formats.

  • What is the purpose of #undef preprocessor?

It is used to undefine an existing macro definition.

  • Explain the use of comma operator (,).

A comma operator can be used to separate two or more expressions.

Eg: printf(“hi”) , printf(“Hello”);

  • When should we use the register storage specifier?

If a variable is used most frequently then it should be declared using register storage specifier, then possibly the compiler gives CPU register for its storage to speed up the lookup of the variable.

  • Where an automatic variable is stored?

Every local variable by default being an auto variable is stored in stack memory.

  • Does a built-in header file contains built-in function definition?

No, the header file only declares function. The definition is in the library which is linked by the linker.

  • S++ or S = S+1, which can be recommended to increment the value by 1 and why?

S++, as it is single machine instruction (INC) internally.

  • Can a program be compiled without main() function?

Yes, it can be but cannot be executed, as the execution requires a main() function definition.

  • Where the address of operator (&) cannot be used?

It cannot be used on constants.

It cannot be used on variables that are declared using the register storage class.

  • Does a break is required by default case in switch statement?

Yes, if it is not appearing as the last case and if we do not want the control to flow to the following case after default if any.

  • Is FILE a built-in data type?

No, it is a structure defined in stdio.h.

  • How many operators are there under the category of ternary operators?

There is only one operator and is a conditional operator (? : ).

Which keyword is used to perform unconditional branching?


  • Which operator is used to receive the variable number of arguments for a function?

Ellipses (…) is used for the same. A general function definition looks as follows

void f(int k,…)  {


  • Which built-in library function can be used to re-size the allocated dynamic memory?


  • Can we assign a float variable to a long integer variable?

Yes, with loss of fractional part.

  • What it the return value of a relational operator if it returns any?

Return a value 1 if the relation between the expressions is true, else 0.

How does bitwise operator XOR work?

If both the corresponding bits are the same it gives 0 else 1.

  • Can a pointer access the array?

Pointer by holding the array’s base address can access the array.

  • To make pointer generic for which date type it need to be declared?


  • What is the built-in function to append one string to another?

strcat() form the header string.h

  • Which operator can be used to access union elements if union variable is a pointer variable?

Arrow (->) operator.

  • Name a function which can be used to close the file stream.


  • Which function can be used to release the dynamic allocated memory?


  • What is the first string in the argument vector w.r.t command line arguments?

Program name.

  • How can we determine whether a file is successfully opened or not using fopen() function?

On failure fopen() returns NULL, otherwise opened successfully.

  • Can a function return multiple values to the caller using return reserved word?

No, only one value can be returned to the caller.

  • Can the structure variable be initialized as soon as it is declared?

Yes, w.r.t the order of structure elements only.

  • Is there a way to compare two structure variables?

There is no such. We need to compare element by element of the structure variables.

Which built-in library function can be used to match a pattern from the string?


  • Can we use just the tag name of structures to declare the variables for the same?

No, we need to use both the keyword ‘struct’ and the tag name.

  • Can the main() function left empty?

Yes, possibly the program doing nothing.

  • Can one function call another?

Yes, any user-defined function can call any function.

  1. Executing a C program involves a series of steps. They are,
  2. Creating the program.
  3. Compiling the program.
  4. Linking the program with functions that are needed from the C library.
  5. Executing the program.
  6. basic difference between float and double variable

Float is of 32 bits (4 bytes) in which 23 bits are used to store mantissa and 8 bits are used for storing exponent and 1 bit is used for the sign. It can hold about 6 to 9 decimal digits

Double is of 64 bits (8 bytes) in which 52 bits are used to store mantissa and 7 bits are used to store the exponent and 1 bit is for a sign. It can hold about 15 to 17 decimal digits.

  • What is the difference between variable declaration and variable definition?

Declaration associates type to the variable whereas definition gives the value to the variable.

  • Why n++ executes faster than n+1?
    The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.
  • What are enumerations?

Enumerations are lists of integer constants with names. Enumerators are defined with the keyword enum.

  • Define function
  • fseek() – It is used to moves the reading control to different positions using fseek function.
    ftell() – It tells the byte location of current position in file pointer.
    rewind() – It moves the control to beginning of a file.
  • Distinguish between malloc() & calloc() memory function

Both allocate memory from heap area/dynamic memory. By default, calloc fills the allocated memory with 0’s.

  • When should the register modifier be used? Does it really help?

The answer is never, with most modern compilers., many compilers actually ignore the register modifier, which is perfectly legal, because it is only a hint and not a directive.

When is a switch statement better than multiple if statements?

A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

  • Define escape sequence

An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly

  • Define Macro

macro is a fragment of code that has been given a name. Whenever the name is used, it is replaced by the contents of the macro.

  • when you pass an array name as an argumet to a function what is actually being passed?

In passing an array as a parameter to a function it is passed as a reference parameter. What is actually passed is the address of its first element.

  • What is the purpose of the keyword void in a function declaration ?

we can say that the purpose of specifying the return type void is that it doesn’t return anything

  • Define Type conversion

It is converting one type of data to another type. It is also known as Type Casting

  • Command line arguemnet

It is the number of arguments passed into the program from the command line, including the name of the program.

  • unable to open stdio.h. what is reason behind it

This error indicates compiler can’t find or open the file ‘STDIO.H’

How does a constant defined by const differ from the constant defined by preprocessor statement #define?

  A #define is used as an immediate constant or as a macro. Whereas the constant is a variable whose value can not change. #define can not define externally, and there is no way to use it for availability to the linker. Whereas the constant can be global

What is the difference between write and append mode of fopen?

Write mode either overwrite the existing file or creates a new one if the file is non-existent. Append mode opens the file and sets the file pointer/cursor to the end of the file so that any write operation may start from the very end of that file.

  • can function return more than one value ?

We cannot return multiple values from a C function. You can either

  1. Return a data structure with multiple values, like a struct or an array.
  2. Pass pointers to the function and modify the values of the pointers inside the function
  • What are the different ways of passing parameters to the functions? Which to use when?
  • Call by value − We send only values to the function as parameters. We choose this if we do not want the actual parameters to be modified with formal parameters but just used.
  • Call by reference − We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters.

  • What is the use of union in C?

A union is a special data type available in C that allows to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time.

     What is the difference between puts and printf?

The similarity is that both are used to display content on the screen.

The difference is puts is used to display only strings. However, printf is used to display integer, float, character, hexa decimal values as well as strings.

strcat function(String Concatenation)

the strcat function appends a copy of the string pointed to by s2 to the end of the string pointed to by s1.

Difference between Arrays and Structures in C

An array is a collection of related data elements of same type. Structure can have elements of different  types.

An array is a derived data type. A structure is a programmer-defined data type. Array allocates static memory.  Structures allocate dynamic

  • use of memset function

The memset() function shall copy c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s.

  • goto and continue statement in c

It is sometimes desirable to skip some statements inside the loop. In such cases, continue statements are used.

goto statement is used for altering the normal sequence of program execution by transferring control to some other part of the program

 How to Declare and Use Constants in the C Language

constants are declared using the C language preprocessor and not the compiler. Here’s the format:

#define VOTING_AGE 18

  • The advantages of using functions are:
  • Avoid repetition of codes.
  • Increases program readability.
  • Divide a complex problem into simpler ones.
  • Reduces chances of error.
  • Modifying a program becomes easier by using function

  • can function return a pointer ?

C programming allows to return an array from a function. Similarly, C also allows to return a pointer from a function.

  • Can we pass argument in macro definition

Function-like macros can take arguments, just like true functions.

3.  What is the difference between fprintf, sprintf and printf?

  • fprintf writes output to a file handle (FILE *).
  • sprintf writes output to a buffer that you allocate(char*).
  • printf writes output to the standard output stream(stdout).
  • use of atoi function

converts a string into an integer numerical representation.

  • Can we access the same memoy location with different union memers

You can define a union with many members, but only one member can contain a value at any given time

  • use of typedf keyword

The purpose of typedef is to assign alternative names to existing types.

  • does recurissve function helpto improve the performance of a program

recursive programming gives the programmer a better way of organizing code in a way that is both maintainable and logically consistent

What is the relationship between array name and pointer in C ?

The name of the array is a constant pointer that contains the memory address of the first element of the array.

  • Define double pointer

pointer that points to another pointer is known as double-pointer.

3.  Why, or when, do you need to dynamically allocate memory in C?

  • You cannot determine the maximum amount of memory to use at compile time;
  • You want to allocate a very large object;
  • You want to build data structures (containers) without a fixed upper size;
  • Use of fseek function with its complete argument list

The fseek() function is used to set the file position indicator for the stream to a new position. This function accepts three arguments.

  • What do you meant by format string?

“format string” that allows you to specify lots of information about how a program is formatted.integer /charcter

Didn't Find Any Subjects/Contents?

Click on the contribute button to contribute subjects materials on Study Notes Nepal.


Leave a Reply

Your email address will not be published. Required fields are marked *

Join Our Facebook Community Group

Study Notes Nepal