Wednesday, 24 January 2018

Control Statement

A control statement is a statement that determines whether other statements will be executed. An if statement decides which statement to execute, or decides which of two statements to execute.

In other words "Control Statement is a statement that control the flow of program compilation. "

"Control Statement are used for spiking some statement for few iteration/time."

"Are also used for execute the same statement to certain time."




Non-Iterative:-











Memory Layout Of a C Program




After writing a C program this is the first question that comes in our mind.


  • Code Section: This part of memory contains the program code,Its usually read only.
  • Data Section: This section contains all the static,global and extern variables defined by the programmer.
    • BSS(uninitialized data):If we are not initialing the static variable or global variable.Lets say we declare an variable: int i; this is initialized to zero default & stored in this section.
    • Initialized data :If we initialize a global or static variable say int i=10;It is stored in this section. 


  •  Heap Section: Dynamic allocated memory using functions such as calloc() and malloc() is stored in this part of the memory.

  • Stack Section: Whenever a function is called in C program,respectively a function stack frame is created,which is eventually destroyed after the call.This function stack frame is stored in stack section.All auto variable which are declared inside the function becomes the part of this memory section.  

FAQ in interviews:

  • Why do we need a BSS segment? Can't we just use memset() to clear the memory and use only one segment in data section?
  • Why do we need a heap section?
  • Where will extern int i=10 gets stored?
  • Where are function arguments stored in C?

Tuesday, 23 January 2018

Type Casting & Type Qualifier

Type Casting :-

Type casting is the way to convert the data from one type to  other type. Exp:- Converting the short int to long int vice versa.


Type of Type Casting:-
  1. Implicit Type Casting
  2. Explicit Type Casting

Implicit Type Casting :-

When Type Casting is performed automatically by the compiler, without programmers intervention, such type of conversion is know as Implicit Type Casting. 

Exp:-  int a = 10, r;
           short  int b = 20; 
          r = a + b ;
// in 32bit OS// int size is 4 byte , short int size 2 byte.
// r and a size is 4 byte and  b size is 2 byte, but when the expression is going to solve the 

Explicit Type Casting :-

When Type Casting is performed forcefully by programmers, that is known as Explicit Type Casting .

Exp:-  Take same example for easy to understand 

          short int a = 10, r;
          int b = 20; 
          r = a + ( short int )b ;

Monday, 22 January 2018

Operators In C



Symbols that are used to perform some operations in a C program are called Operators.



Operators are categorized as:-

  1. Unary Operator(Uses One Operand)
  2. Secondary Operator(Uses Two Operands)
  3. Ternary Operator (Uses Three Operands)

Type Of Operators In C  :-

Ignore Comma, Comma itself an Operator
  • Arithmetic Operators                  (Exp:- +, -, *, /,%  ) 
  • Relational Operators                   (Exp:- >, >=, <=,<, ==, =!)
  • Logical Operators                       (Exp:- &&, || , ! )
  • Assignment Operators                (Exp:- = )
  • Bit Wise Operators                     (Exp:- &, |, ^, ~ )
  • Size Of Operator                        (Exp:-  sizeof()  )
  • Comma Operator                        (Exp:-    ,    )
  • Inc and Dec Operator                 (Exp:- ++, -- )
  • Conditional Operators                (Exp:- condition?true:false  ) 
  • Address Operator                        (Exp:- &(reference operator )  )
  • De-reference Operator                (Exp:- *  )
Many more are there that will discuss in coming posts.  

Frequently Ask Questions In Interview :-

  1. Tell us 5 Unary Operators.
  2. Example of Ternary operator. (You should take a situation ; then explain) 







Tuesday, 16 January 2018

Data Type

Variables in C have associated data types. Each data type requires different amounts of memory and has some specific operations which can be performed over it.

Basically there are two types of data in C :- 

  1. Primary Data Type
  2. Secondary Data Type

Primary Data Type :- 
          Primary data type is Pre-defined by C itself.
  • int
  • char
  • float 
  • double
Secondary Data Type :-
         Secondary data type are defined by the help of primary data types.
  • array
  • pointer
  • structure
  • union
  • enum
  • typedef
Structure, Union, Enum & Typedef are also known as User Defined Data Type.
In upcoming post we will discuss data types in detail.


Thursday, 4 January 2018

Type of errors in C


Error is an abnormal condition whenever it occurs,execution of program stops,It can be classified as:

1) Compile time error

2) Run time error



1) Compile time error :-


  • Pre-processor error
  Here I missed "i" in first instruction then got error as below













  • Translator 

Here I missed ";" then got error as below










  • Linker

2) Run time error :-

  • Segmentation fault
  • Bus Error