Wednesday, July 17, 2013

Programming and Data Structure

In this post, I am going to cover all the topics related to GATE and other technical interviews which comes under programming in C and Data Structure.
C is the most basic fundamental language that every CS/IT engineer should know. Also I would say everyone should know at least one computer programming language to understand this fastest growing digital world. Currently we are using many highly technical gadgets those are very user friendly, but one should know after how much effort that product is available to use by a totally non-technical person.
In this post I am going to cover most fundamental concepts of computer science those every Software Engineer should know.

Followings are the important topics related to Programming and Data Structure:

  1. What is C Programming Language
  2. Scope
  3. Binding
  4. Abstract Data Types
  5. Array
  6. Pointer
  7. Stack
  8. Queues
  9. Functions
  10. Recursion
  11. Parameter Passing
  12. Link List
  13. Trees
  14. Binary Search Tree
  15. Binary Heap

What is C Programming Language

C is a programming language developed in 1972 by Dennis Ritchie in Bell Lab. C is reliable, simple, and easy to use. If you know C then you can quickly learn any programming language. No one can directly learn C++ or JAVA, so C is the first step for programming learner. Like a child can not start talking directly without learning words. So in simple language C is the letters and words and Grammar of programming languages.

We can compare C language with any spoken language for example:English

In English language we have:

Alphabets                                   --> Words                                    --> Sentences   -->   Paragraph

Similarly in C language we have

Alphabets, Digits, Special Symbol --> Constants, Variables, Keywords --> Instructions --> Programs

Alphabets similar to English language, digits (0-9), special symbols like (~,!,@,#,$,%,^,&, etc.)

Constants are of two types: Primary constants and Secondary constants

Primary constants are followings:

  • Integer Constants
  • Real Constants (Fractional, exponential)
  • Characters Constants

Secondary constants are followings:

  • Array
  • Pointer
  • Structure
  • Union
  • Enum

Scope

The scope is the context within the program in which an identifier/ variable is valid and can be resolved to find the entity associated to the identifier. A scope in any programming is a region of the program where a defined variable can have its existence and beyond that variable can not be accessed. There are three places where variables can be declared in C programming language.

  1. Inside a function or a block which is called local variables
  2. Outside of all functions which is called global variables
  3. In the definition of function parameters which is called parameters

Local Variables

Local variables are the variables declared inside a function or any block. They can be used only by statements that are inside that function or block of code. They can not be used outside that function or block in which they have been declared. For example in below code var1, var2, var3 are local variables

#include <stdio.h>  
#include <conio.h>
/* declaration of global variable*/
int global_var;

int main(){
    
     /* declaration of local variables  */
    int var1;
    int var2;
    int var3;
    
    /* initialization of local variables */
    var1 = 10;
    var2 = 20;
    var3 = var1 + var2;
    global_var = var3 + 1;
    printf ("Value of var1 = %d, var2 = %d and var3 = %d\n", var1, var2, var3);
    printf ("Global variable global_var = %d\n", global_var);
    system("pause");
    return 0;
}

Global Variables

Global variables are defined outside of a function, usually on top of the program. The global variables will hold their value throughout the lifetime of your program and they can be accessed inside any of the functions defined for the program.

A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration. In above example global_var is a global variable declared on top that can be used in any function.

Function

Function ........

No comments:

Post a Comment