The following are the differences between structures and arrays:

– Array elements are homogeneous.

-Structure elements are of different data type.
– Array allocates static memory and uses index / subscript for accessing elements of the array.

-Structures allocate dynamic memory and uses (.) operator for accessing the member of a structure.
– Array is a pointer to the first element of it.

-Structure is not a pointer
– Array element access takes less time in comparison with structures.     



String constants

                 A string constant consists of zero or more character enclosed in quotation marks. Several string constants are given below.

       “Welcome to C Programming”                      “ ”

        “a+b\n”                                                          “Error\a\a\a”

                There is a difference between the constant ‘A’ and “A” in C, the first ‘A’ is a character constant while the second “A” is string constant. The notation ‘A’ is a constant occupying a single byte containing the ASCII code of the character A. The notation  “A”  on the other hand ,is a constant that occupies two bytes one for ASCII code of A and another for the null character with the value 0,that terminates all the string.


Top-down and bottom-up design

Top-down and bottom-up are both strategies of information processing and knowledge ordering, used in a variety of fields including software, humanistic and scientific theories (see systemics), and management and organization. In practice, they can be seen as a style of thinking and teaching.

top-down approach (also known as stepwise design or deductive reasoning, and in many cases used as a synonym of analysis or decomposition) is essentially the breaking down of a system to gain insight into its compositional sub-systems. In a top-down approach an overview of the system is formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of “black boxes”, these make it easier to manipulate. However, black boxes may fail to elucidate elementary mechanisms or be detailed enough to realistically validate the model. Top down approach starts with the big picture. It breaks down from there into smaller segments.

bottom-up approach (also known as inductive reasoning, and in many cases used as a synonym of synthesis) is the piecing together of systems to give rise to grander systems, thus making the original systems sub-systems of the emergent system. Bottom-up processing is a type of information processing based on incoming data from the environment to form a perception. Information enters the eyes in one direction (input), and is then turned into an image by the brain that can be interpreted and recognized as a perception (output). In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed. This strategy often resembles a “seed” model, whereby the beginnings are small but eventually grow in complexity and completeness. However, “organic strategies” may result in a tangle of elements and subsystems, developed in isolation and subject to local optimization as opposed to meeting a global purpose.




Macro is preprocessed

Function is compiled

No type checking

Type checking is done

Code length increases

Code length remains same

Use of macro can lead to side effect

No side effect

Speed of execution is faster

During function call, transfer of control takes place

Useful where small code appears many time

Useful where large code appears many time

Generally Macros do not extend beyond one line

Function can be of any number of lines

Macro does not check compile errors

Function checks compile errors

Difference between break and continue in C?

The break statement will immediately jump to the end of the current block of code. 

The continue statement will skip the rest of the code in the current loop block and will return to the evaluation part of the loop. In a do or while loop, the condition will be tested and the loop will keep executing or exit as necessary. In a for loop, the counting expression (rightmost part of the for loop declaration) will be evaluated and then the condition will be tested.


#include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf(“Hello %d\n”, i ); } }
#include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf(“Hello %d\n”, i ); } }
#include main() { int i; int j = 10; for( i = 0; i <= j; i ++ ) { if( i == 5 ) { continue; } printf(“Hello %d\n”, i ); } }

for(int i = 0; i < 10; i++){
if(i == 0) continue;

will not execute DoSomeThingWith for i = 0, but the loop will continue and DoSomeThingWith will be executed for i = 1 to i = 9.

differ b/w pre increment and post increment

++x is pre-increment and x++ is post-increment that is in the first x is incremented before being used and in the second x is incremented after being used.

This is most easily demonstrated with a small program.

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  4. int main(int argc, char **argp)
  5. {
  6.     int x = 5;
  8.     printf(“x=%d\n”, ++x);
  9.     printf(“x=%d\n”, x++);
  10.     printf(“x=%d\n”, x);
  12.     return EXIT_SUCCESS;
  13. }
  14. The output of this program is
    Expand|Select|Wrap|Line Numbers
    1. x=6
    2. x=6
    3. x=7

    In the first printf statement x is incremented before being passed to printf so the value 6 is output, in the second x is passed to printf (so 6 is output) and then incremented and the 3rd printf statement just shows that post increment following the previous statement by outputting x again which now has the value 7.