C FUNDAMENTALS

C FUNDAMENTALS

C FUNDAMENTALS



☆ STRUCTURE OF A PROGRAM :



  
  
  
#include <stdio.h>

void main()
{
  printf("HELLO WORLD");
}
  
  
  

  1. #include <stdio.h>

    It is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.


  2. void main()

    It is the main function where the program execution begins.


  3. printf()

    It is the function which prints the statements inside in it.



☆ COMPILATION AND EXECUTION OF A PROGRAM :


  1. Once the program has been entered into the computer, edited and saved, it can be compiled and executed by selecting Run option.

  2. A new window will then be opened, and will compile the current program.

  3. If the program does not compile successfully, a list of error messages will appear.

  4. Each error message indicates the line number where the error was detected as well as the type of error.

  5. If the program compile successfully, it will begin to execute it immediately, prompting for input, displaying output, etc., within the new window.

☆ CHARACTER SET :


  1. C uses the uppercase letters A to Z, the lowercase letters a to z, the digits 0 to 9.

  2. It also uses certain special characters as building blocks to form basic program elements (e.g., constants, variables, operators, expressions, etc.).

  3. C uses certain combinations of characters, such as \b, \n and \ t,to represent special conditions such as backspace, newline and horizontal tab, respectively.

  4. These character combinations are known as escape sequences.

☆ IDENTIFIERS AND KEYWORDS :


  1. IDENTIFIERS :

    1. ldentifiers are names that are given to various program elements, such as variables, functions and arrays.

    2. Identifiers consist of letters and digits,underscore,etc.

    3. RULES :

      • First letter should be alphabet.

      • It can begin with underscore( _ ).

      • Keywords should not be used as variables.

      • Variables should resembles their meaning.


    4. SYNTAX : datatype variable_name;

  2. KEYWORDS :

    1. Keywords are the reserved word in C.

    2. Keywords have standard, predefined meanings in C.

    3. These keywords can be used only for their intendedpurpose

    4. they cannot be used as programmer-defined identifiers.

    5. The standard keywords are :

      • void,int,float,char,double
      • if,else,for,while,do
      • switch,case,break,continue
      • struct,union,sizeof,return
      • long,short,signed,unsigned
      • auto,typedef,static,etc.


☆ DATA TYPES :


DATATYPES DESCRIPTION MEMORY REQUIREMENTS
int It holds integer quantity.
RANGE : -32768 to 32767
2 BYTES
char It holds a single character.
RANGE : -128 to 127
1 BYTES
float It holds floating-point (decimal) number. 4 BYTES (1 WORDS)
double It holds double-precision floating-point number (i.e.,more significant figures). 8 BYTES (2 WORDS)

    
    
//accepting various types of data and printing them

#include <stdio.h>
void main()
{

    int a;
    float b;
    char sub[5];
    
    printf("ENTER ANY INTEGER VALUE :");
    scanf("%d",&a);
    
    printf("\nENTER ANY FLOAT VALUE :");
    scanf("%f",&b);
     
    printf("\nENTER ANY SUBJECT NAME :");
    scanf("%s",sub);
      
    printf("\nINTEGER : %d",a);
    printf("\nFLOAT : %f",b);  
    printf("\nSTRING : %s",sub);
    
}
    
    

☆ CONSTANTS :


  1. There are four basic types of constants in C.

  2. They are integer constants,floating-pointconstants,character constants and string constants.

  3. The following rules apply to all numeric-type constants :

    • Commas and blank spaces cannot be includedwithin the constant.

    • The constant can be preceded by a minus (-) sign if desired.

    • The value of a constant cannot exceed specified minimum and maximum bounds.

☆ VARIABLES AND ARRAYS :


  1. VARIABLES :


    1. A variable is an identifier that is used to represent some specified type of information within a designated portion of the program.

    2. In its simplest form, a variable is an identifier that is used to represent a single data item; i.e., a numerical quantity or a character constant.

    3. The data item must be assigned to the variable at some point in the program. The data item can then be accessed later in the program simply by referring to the variable name.


  2. ARRAYS :


    1. The array is another kind of variable that is used extensively in C. An array is an identifier that refers to a collection of data items that all have the same name.

    2. The data items must all be of the same type (e.g., all integers, all characters, etc.). The individual data items are represented by their corresponding array-elements (i.e., the first data item is represented by the first array element, etc.).

    3. The individual array elements are distinguished from one another by the value that is assigned to a subscript.



☆ DECLARATIONS , EXPRESSIONS , STATEMENTS :


  1. DECLARATIONS :


    1. A declaration associates a group of variables with a specific data type.

    2. All variables must be declared before they can appear in executable statements.

    3. A declaration consists of a data type, followed by one or more variable names, ending with a semicolon.


  2. EXPRESSIONS :


    1. An expression represents a single data item, such as a number or a character.

    2. The expression may consist of a single entity, such as a constant, a variable, an array element or a reference to a function. It may also consist of some combination of such entities, interconnected by one or more operators.

    3. The use of expressions involving operators is particularly common in C, as in most other programming languages.


  3. STATEMENTS :


    1. A statement causes the computer to carry out some action. There are three different classes of statements in C. They are expression statements, compound statements and control statements.

    2. An expression statement consists of an expression followed by a semicolon.

    3. The execution of an expression statement causes the expression to be evaluated.



☆ SYMBOLIC CONSTANT :


  1. A symbolic constant is a name that substitutes for a sequence of characters. The characters may represent a numeric constant, a character constant or a string constant. Thus, a symbolic constant allows a name to appear in place of a numeric constant, a character constant or a string.

  2. When a program is compiled, each occurrence of a symbolic constant is replaced by its corresponding character sequence.

  3. Symbolic constants are usually defined at the beginning of a program. The symbolic constants may then appear later in the program in place of the numeric constants, character constants, etc. that the symbolic constants represent.

  4. SYNTAX :
  5. #define name text;
    ,where name represents a symbolic name, typically written in uppercase letters, and text represents the sequence of characters that is associated with the symbolic name.

    
    
//demonstrating the use of SYMBOLIC CONSTANT

#include <stdio.h>
#define NUM 100
void main()
{
   
   int a,b=50;
   a=NUM+b;
   printf("%d",a);
    
}
    
    

Comments