Basic Idea Of C Langues

 

 Hello Disha Please Read This 

Basic Idea C and C++ .Most Important This In Life Don't More Introduction Lets Go

C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Eqquipment Corporation PDP-11 computer in 1972.

The Unix operating system and virtually all Unix applications are written in the C language. 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 computers.

  • Facts about C

    • C was invented to write an operating system called UNIX.

    • C is a successor of B language which was introduced around 1970

    • The language was formalized in 1988 by the American National Standard Institue (ANSI).

    • By 1973 UNIX OS almost totally written in C.

    • Today C is the most widely used System Programming Language.

    • Most of the state of the art software have been implemented using C

    Why to use C ?

    C was initially used for system development work, in particular the programs that make-up the operating system. C was adoped as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be:

    • Operating Systems
    • Language Compilers
    • Assemblers
    • Text Editors
    • Print Spoolers
    • Network Drivers
    • Modern Programs
    • Data Bases
    • Language Interpreters
    • Utilities

    • Disha This Simple Introduction Of C.
    • Lest See Example Introduction

    Tokens in C

    • A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens −

      printf("Hello, World! \n");

      The individual tokens are −

      printf
      (
         "Hello, World! \n"
      )
      ;

    Semicolons

    • In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.

      Given below are two different statements −

      printf("Hello, World! \n");
      return 0;

    Comments

    • Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below −

      /* my first program in C */
      

      You cannot have comments within comments and they do not occur within a string or character literals.

    Identifiers

    • A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9).

      C does not allow punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers −

      mohd       zara    abc   move_name  a_123
      myname50   _temp   j     a23b9      retVal
      

    Keywords

    • 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.

      autoelselongswitch
      breakenumregistertypedef
      caseexternreturnunion
      charfloatshortunsigned
      constforsignedvoid
      continuegotosizeofvolatile
      defaultifstaticwhile
      dointstruct_Packed
      double

    Whitespace in C

    • A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.

      Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement −

      int age;

      there must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement −

      fruit = apples + oranges;   // get the total fruit

      no whitespace characters are necessary between fruit and =, or between = and apples, although you are free to include some if you wish to increase readability.

    Disha Best Topic THis C Variable Please complete Read This 

    • A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

      The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive. Based on the basic types explained in the previous chapter, there will be the following basic variable types −

      Sr.No.Type & Description
      1

      char

      Typically a single octet(one byte). It is an integer type.

      2

      int

      The most natural size of integer for the machine.

      3

      float

      A single-precision floating point value.

      4

      double

      A double-precision floating point value.

      5

      void

      Represents the absence of type.

      C programming language also allows to define various other types of variables, which we will cover in subsequent chapters like Enumeration, Pointer, Array, Structure, Union, etc. For this chapter, let us study only basic variable types.

    Variable Definition in C

    • A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type and contains a list of one or more variables of that type as follows −

      type variable_list;
      

      Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object; and variable_list may consist of one or more identifier names separated by commas. Some valid declarations are shown here −

      int    i, j, k;
      char   c, ch;
      float  f, salary;
      double d;
      

      The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to create variables named i, j and k of type int.

      Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows −

      type variable_name = value;
      

      Some examples are −

      extern int d = 3, f = 5;    // declaration of d and f. 
      int d = 3, f = 5;           // definition and initializing d and f. 
      byte z = 22;                // definition and initializes z. 
      char x = 'x';               // the variable x has the value 'x'.
      

      For definition without an initializer: variables with static storage duration are implicitly initialized with NULL (all bytes have the value 0); the initial value of all other variables are undefined.

    Variable Declaration in C

    • A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable. A variable definition has its meaning at the time of compilation only, the compiler needs actual variable definition at the time of linking the program.

      A variable declaration is useful when you are using multiple files and you define your variable in one of the files which will be available at the time of linking of the program. You will use the keyword extern to declare a variable at any place. Though you can declare a variable multiple times in your C program, it can be defined only once in a file, a function, or a block of code.

    Example

    • Try the following example, where variables have been declared at the top, but they have been defined and initialized inside the main function −

      #include <stdio.h>
      
      // Variable declaration:
      extern int a, b;
      extern int c;
      extern float f;
      
      int main () {
      
         /* variable definition: */
         int a, b;
         int c;
         float f;
       
         /* actual initialization */
         a = 10;
         b = 20;
        
         c = a + b;
         printf("value of c : %d \n", c);
      
         f = 70.0/3.0;
         printf("value of f : %f \n", f);
       
         return 0;
      }

      When the above code is compiled and executed, it produces the following result −

      value of c : 30
      value of f : 23.333334
      

      The same concept applies on function declaration where you provide a function name at the time of its declaration and its actual definition can be given anywhere else. For example −

      // function declaration
      int func();
      
      int main() {
      
         // function call
         int i = func();
      }
      
      // function definition
      int func() {
         return 0;
      }

    Lvalues and Rvalues in C

    • There are two kinds of expressions in C −

      • lvalue − Expressions that refer to a memory location are called "lvalue" expressions. An lvalue may appear as either the left-hand or right-hand side of an assignment.

      • rvalue − The term rvalue refers to a data value that is stored at some address in memory. An rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.

      Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side. Take a look at the following valid and invalid statements −

      int g = 20; // valid statem Baent
      
      10 = 20; // invalid statement; would generate compile-time error

Comments

  1. Your Blog are completely remarkable and share worthy. I really appreciate your efforts that you put on this. Keep sharing.
    C++ Training Institute in South Delhi

    ReplyDelete

Post a Comment