C language tutorial with programming approch for beginners and professionals helps you to understand the c language tutorial easily.
C is one of the most popular and widely used programming language, used to develop system application software.
C language can be define in various ways :
1) Mother language
2) System Programming Language
3) Procedure Oriented Programming Language
4) Structured Programming Language
5) Mid Level Programming Language
You should know before starting c tutorial
To learn C Programming language you haven’t required any previous programming knowledge, but the basic understanding of any other programming languages will help you to understand the C programming concepts quickly.
Hello world! program in C
C Basic Syntax
Types of C Variables
As we saw earlier, an entity that may vary during program execution is called a variable. Variable names are names given to locations in memory. These locations can contain integer, real or character constants. In any language, the types of variables that it can support depend on the types of constants that it can handle. This is because a particular type of variable can hold only the same type of constant. For example, an integer variable can hold only an integer constant, a real variable can hold only a real constant and a character variable can hold only a character constant. The rules for constructing different types of constants are different. However, for constructing variable names of all types the same set of rules apply. These rules are given below. Rules for Constructing Variable Names (a) (b) (c) (d) A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable names as it adds to your typing effort. The first character in the variable name must be an alphabet or underscore. No commas or blanks are allowed within a variable name. No special symbol other than an underscore (as in gross_sal) can be used in a variable name. Ex.: si_int m_hra pop_e_89 These rules remain same for all the types of primary and secondary variables. Naturally, the question follows… how is C able to differentiate between these variables? This is a rather simple matter. C compiler is able to distinguish between the variable names by making it compulsory for you to declare the type of any variable name that you wish to use in a program. This type declaration is done at the beginning of the program. Following are the examples of type declaration statements: Ex.: int si, m_hra ; float bassal ; char code ; Since, the maximum allowable length of a variable name is 31 characters, an enormous number of variable names can be constructed using the above-mentioned rules. It is a good practice to exploit this enormous choice in naming variables by using meaningful variable names. Thus, if we want to calculate simple interest, it is always advisable to construct meaningful variable names like prin, roi, noy to represent Principle, Rate of interest and Number of years rather than using the variables a, b, c.
Keywords are the words whose meaning has already been explained to the C compiler (or in a broad sense to the computer). The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. Some C compilers allow you to construct variable names that exactly resemble the keywords. However, it would be safer not to mix up the variable names and the keywords. The keywords are also called ‘Reserved words’. There are only 32 keywords available in C. Figure 1.5 gives a list of these keywords for your ready reference. A detailed discussion of each of these keywords would be taken up in later chapters wherever their use is relevant.
%f for printing real values
%d for printing integer values
%c for printing character values
Datatype—— Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we can use in our program. These datatypes have different storage capacities.C language supports 2 different type of data types:
Primary data types:These are fundamental data types in C namely integer(int), floating point(float), character(char) and void.
Derived data types:Derived data types are nothing but primary datatypes but a little twisted or grouped together like array, stucture, union and pointer. These are discussed in details later.
Data type determines the type of data a variable will hold. If a variable x is declared as int. it means x can hold only integer values. Every variable which is used in the program must be declared as what data-type it is.
- FLOATING POINT
Integers are used to store whole numbers.
Size and range of Integer type on 16 bit machine:
Floating point type
Floating types are used to store real numbers.Size and range of Integer type on 16-bit machine
Character types are used to store characters value.Size and range of Integer type on 16-bit machine
void typevoid type means no value. This is usually used to specify the type of functions which returns nothing. We will get acquainted to this datatype as we start learning more advanced topics in C language, like functions, pointers etc.