C Language

C   is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons −
  • Easy to learn
  • Structured language
  • It produces efficient programs
  • It can handle low-level activities
  • It can be compiled on a variety of computer platforms
  • C was invented to write an operating system called UNIX.
  • C is a successor of B language which was introduced around the early 1970s.
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • The UNIX OS was totally written in C.
  • Today C is the most widely used and popular System Programming Language.
  • Most of the state-of-the-art software have been implemented using C.
  • Today's most popular Linux OS and RDBMS MySQL have been written in C.
  • The following list shows the reserved words in C. These reserved words may not be used as constants or variables or any other identifier names.
    auto else long switch
    break enum register typedef
    case extern return union
    char float short unsigned
    const for signed void
    continue goto sizeof volatile
    default if static while
    do int struct double
    Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The types in C can be classified as follows −
    S.N. Types & Description
    1. Basic Types
    They are arithmetic types and are further classified into: (a) integer types and (b) floating-point types.
    2. Enumerated Types
    They are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program.
    3. The Type void
    The type specifier void indicates that no value is available.
    4. Deriveds Types
    They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
    A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions.
    You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division is such that each function performs a specific task.
    Defining a Function:

    return_type function_name( parameter list ){
    body of the function

    A function definition in C programming consists of a function header and a function body. Here are all the parts of a function −
  • Return Types :
  • A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
  • Function Name :
  • This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • Parameters :
  • A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
  • Function Body :
  • The function body contains a collection of statements that define what the function does.
  • Example :

  • /* function returning the max between two numbers */
    int max(int num1, int num2) {
       /* local variable declaration */
       int result;
       if (num1 > num2)
          result = num1;
          result = num2;
       return result; 

    What are pointers ?
    A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location.
    Like any variable or constant, you must declare a pointer before using it to store any variable address.
    The general form of a pointer variable declaration is −
    type *var-name;
    Here, type is the pointer's base type; it must be a valid C data type and var-name is the name of the pointer variable.
    The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.
    Take a look at some of the valid pointer declarations −
    int    *ip;    /* pointer to an integer */
    double *dp;    /* pointer to a double */
    float  *fp;    /* pointer to a float */
    char   *ch     /* pointer to a character */

    How to use pointers ?
    There are a few important operations, which we will do with the help of pointers very frequently. (a) We define a pointer variable, (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand. The following example makes use of these operations −

    #include <stdio.h>
    int main () {
    int  var = 20;   /* actual variable declaration */
    int  *ip;        /* pointer variable declaration */
    ip = &var;  /* store address of var in pointer variable*/
    printf("Address of var variable: %x\n", &var  );
    /* address stored in pointer variable */
    printf("Address stored in ip variable: %x\n", ip );
    /* access the value using the pointer */
    printf("Value of *ip variable: %d\n", *ip );
    return 0;

    When the above code is compiled and executed, it produces the following result −
    Address of var variable: bffd8b3c
    Address stored in ip variable: bffd8b3c
    Value of *ip variable: 20
    Home Test Tutorials Program About Us