Skip to main content

C Language Notes for new Students


   C- LANGUAGE NOTES 
-----------------------------------------------------------------------------

Dennis Ritchie




    1. C language is generally develop for hardware programming
    2. C language is developed by Dennis Ritchie.
    3. C language is developing in 1969-1974.
    4. C language is develop in AT & T Bell Laboratory

Programming Language:-
Programming Language provide interface for write the program for development of Software.
There are different types of programming language.
    a) Low Level:-
            I) Machine Language: - It is in the form of Binary Numbers (0 or 1)
            ii) Assembly Language: - It is in the form of group of alphabets and numbers.
    b) High Level:-
            --> It is user understandable language.
            --> Program’s are written by the help of Alphabet number and symbols.
            --> Programming is very easy in High Level Language.
            --> Translator's are used for translate the program in machine level.
    c) 4th Generation & 5th Generation:-
            --> It is next generation language
            --> It is use in Artificial Intelligence
    Translator:-
            Translator is use to convert the program in high level to machine                  
             understandable format.
    There are different types of translator:-
            1. Compiler:-
                        --> It can compile the program at a time.
                        --> Error removing and debugging is slow.
                        --> Fast execution.
            2. Interpreter
                        --> It can interpret the program line by line.
                        --> Error removing and debugging is fast.
                        --> Slow Execution.
Programming Elements:-
            For creating a program different types of elements are used.
Like:-
        a)     Variable & Constant:-
     1. Variable is use to hold the value in program.
     2. Variable is a name of memory location where value is store.
     3. Variable values can be change during program execution.
     4. Constants are not change when the program in run.
            Like:-
                        x=3; here x is a variable and 3 is a value/Constant.
Rules for declaration of a variable:-
1. Variable first character must be started with an alphabet or underscore also.
2. Variable name cannot accept any space.
3. Don't use any special symbol for variable name. Only use underscore symbol
4. Keywords are not use as name of variable.
5. Variable cannot define as more than one time.
            Like:-
                        x, ab123, DOB, gender, _a.
    Wrong variable name: - 1a, D O B, int
Data Types:-
Data Types is used in program to identify the value of a variable. There are different types of data types.
Data Type                Format Specifier
   1.     Int                               %d     
   2.     char                            %c
   3.     float                           %f
   4.     double                       %lf 
   5.     long int                      %ld
   6.     long float                  %lf
Header Files:-
Header files store the definition of the predefine function of c language.
Extension of header file is .h
There are different types of header files.
    a)     stdio.h
    b)    conio.h
    c)     process.h
    d)    math.h
    e)     stdlib.h
    f)      string.h
    g)     iostream.h
etc...
Note:-
    a)     All header files are store in include name directory.
    b)    Header files are always written before main () method using # symbol.
    c)     # is pre-processor directives that can load header files into compiler.
 Function:-
Function is the group of statement. Function provide modular programming approach.
There are different types of function
       a)     Pre Define Function
       b)    User Define function
User define function is define by the user according to the need.
Pre-Define Function:-
            Pre-define function is also known as library function.
There are different types of function.
Like :- printf(), scanf(), clrscr()  etc...
Structure of c program:-
            #include<headerFile.h>
            .
            .
            void main()
            {
                        Variable Declaration;
                        Statement of code;
                        ------------------------------ ;
                        ------------------------------ ;
            }
Note:-
{ , } is curly brackets which is use for scope or body block declaration.
main() -> It is user define function. Programs are always start from main() block.
void :- it ignore the warning i.e. FUNCTION SHOULD RETURN A VALUE
Variable Declaration: - All the variable is define in this section.
Statements of Code:- Hear start the user line of program codes.
C language Software:-

  •        Turbo C
  •        Turbo C++
  •        Borland C
  •        Dev C
  •        Visual C++
   Open c language software for programming:-
STEPS FOR TURBO C++ FOR WINDOWS 7,8
      1.     Click Start Menu.
      2.     Select All Programs.
      3.     Click Turbo C++ for Windows 7
           
                                    Double Click on Turbo C++ Windows 7 icon.
     1.     A window is open. This window is called Editor Window or Code Window

2.     Click File menu and select New option
     3.     Type your code.
     4.     Save your Program with a name and extension is .c
Like:- Prog1.c (here Prog 1 is file name and .c is extension)

     5.     Click on Compile Menu and select compile(ALT+F9) option.
     6.     Click on Run Menu and select Run (CTRL + F9) option.
Important Shortcut for c programming:-
    1.     OPEN -> F3
    2.     SAVE -> F2
    3.     COMPILE -> ALT + F9
    4.     RUN -> CTRL + F9
    5.     OUTPUT -> ALT + F5
    6.     LINE BY LINE CHECK -> F7
    7.     COPY -> CTRL + INSERT
    8.     CUT -> SHIFT + DEL
    9.     PASTE -> SHIFT + INSERT
    10.   UNDO -> ALT + BACKSPACE
    11.   REDO -> ALT + SHIFT + BACKSPACE
    12.   MAXIMIZE DOCUMENT -> F5
    13.   MAKE EXE -> F9
    14.   MAXIMIZE/ MINIMIZE PROGRAM -> ALT + ENTER
    15.   CLOSE -> ALT + F3
   16.    EXIT -> ALT + X
Output Function:-
printf(“Message”);
printf is a function which is use to print the message on the screen.
Syntax:-  printf(“Message of Format Specifier”,variable_list);
example:-
      printf(“Hello”);
      printf(“sum=%d”,a);
Here %d is use for printing the value of a that initialized as int type.
SIMPLE PROGRAM:-
Que 1:- Write a program to print your name .
Ans- 1:-
                #include<stdio.h>
            void main()
            {
                        clrscr();
printf(“Congratulation!! ”);
printf(“HELLO Programmer ! This is my first Programming “);
getch();
            }

  
Some useful function :-
clrscr() -> It is use to clear the output screen.
getch() -> it is use to stop the output screen.

Escape Sequence Character:-
            \n -> for new line
            \t -> for tab space ( 5 character)
            \b -> for move the cursor at back to single character
            \r -> Move cursor at first character of line
            \a -> for beep ( sound)

         
Example:-
            printf(“\n HELLO “);
            printf(“WELCOME\t C programming”);
            output:-
                        welcome       c programming
            printf(“NeuTron\bN”);
            output:-
                        NeuTroN ( last character n is replace with N)
Input Function
scanf() function is use to take input from the keyboard.
Syntax:-        scanf(“Format Specifier......”,&variable List...);
& -> It is ampercent sing and also known as address operator that specify the address of any variable.
Format Specifier:-  It provide the identification of variable value.
Example:-
            For Integer value:-
                        int a;
                        scanf(“%d”,&a);
For Integer value:-
                        float x;
                        scanf(“%f”,&x);

For Integer value:-
                        char z;
                        scanf(“%c”,&z);
Note:- If & operator is not use in scanf() with variable the the input value can not store in the variable.
            Like :- scanf(“%d”,a); -> here &a is required for storing value.
Comma (,) delimiter is use for define multiple value or variable.
Like:-
            Int a,b,c;
            scanf(“%d%d%d”,&a,&b,&c);
Note:- Remember sequence of variable must be important. (Left to Right)
Some Special Types of Input using scanf()
scanf(“%d/%d/%d”,&dd,&mm,&yyyy);    input format:- 12/09/1995


Conditional Statements:-
            The conditional statements is use to check the condition and implementation logic in program to solve a problem.
There are different types of conditional statements
a)     if
b)    if....else
c)     ladder if
d)    nested if
e)     ternary operator
In conditional statements, some operators are use for check the condition.
Like:-
Relational or comparison operator:
a)     > (greater than)
b)    < (less than)
c)     >= (greater or equal to)
d)    <= (less or equal to)
e)    == (equal to)
f)      != (not equal to)
Logical Operator:
a)     && (AND)
b)    || (OR)
c)     ! (NOT)
NOTE :-
            Logical operator is use when multiple condition are checked.
AND (&&)
CONDITION-1
CONDITION-2
RESULTS
TRUE
TRUE
TRUE
TRUE
FALSE
FALSE
FALSE
TRUE
FALSE
FALSE
FALSE
FALSE

OR(||)
CONDITION-1
CONDITION-2
RESULTS
TRUE
TRUE
TRUE
FALSE
TRUE
TRUE
TRUE
FALSE
TRUE
FALSE
FALSE
FALSE

NOT(!)
CONDITION
RESULT
TRUE
FALSE
FALSE
TRUE

CONDITIONAL STATEMENT:
1    .     If
SYNTAX:-
If condition is     
True then
execute
 if block

                                    if(Check condition)
                                    {
                                                -------------- Statements..
                                                --------------
                                    }



2     .     If.. else
SYNTAX:-
                                    if(Check condition)
                                    {
                                                -------------- Statements..
                                                --------------
                                    }
                        else
                                    {
                                                -------------- Statements..
                                                --------------
                                    }
Remember in else, there is no need to define any condition.


3.     Ladder if( if .. else if...) :- This is used when multiple condition is executed.

SYNTAX:-
                                                if(Check condition)
                                                {
                                                                -------------- Statements..
                                                                --------------
                                                }
                                else if(Check condition)
                                                {
                                                                -------------- Statements..
                                                                --------------
                                                }
else if(Check condition)
                                                {
                                                                -------------- Statements..
                                                                --------------
                                                }
                                                .
                                                .               More than one else if
                                                .
                                else
                                                {
                                                                -------------- Statements..
                                                                --------------
                                                }
Note:- Remember always define else at the last because when any condition is not TRUE then else is executed.


4.     Nested if :- It is use when multiple level of condition’s are checked.
SYNTAX
if(Check condition)
                                                {
                                                                if(Check condition)
                                                                {
                                                                                -------------- Statements..
                                                                                -------------- Statements..
                                                                }             
                                                                else
                                                                {
                                                                                -------------- Statements..
                                                                                -------------- Statements..
                                                                }
                                                }
else
                                                {
                                                                if(Check condition)
                                                                {
                                                                                -------------- Statements..
                                                                                -------------- Statements..
                                                                }             
                                                                else
                                                                {
                                                                                -------------- Statements..
                                                                                -------------- Statements..
                                                                }
                                                }


5.      Ternary Operator:- Using ternary operator the condition is checked without using any if and else statements.
SYNTAX:-
      Result_Variable=(check Condition)?True Statements: False Statements;                
Like:-
      Int a=2,b=3;
      int res=(a>b)?a:b;
Result is 3 because condition is false then res store value of b.


Comments

  1. Sir I want to full details of Mac address
    Like :what's the Mac address
    What's we can by Mac address
    also same type details....

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

O Level Practical Queestion Paper (MS-OFFICE, MSDOS, MS-EXCEL, ICT Resources)

MSDOS 1. Write command to display all files having extension ‘jpg’. 2. Write command to display all files of all types starting with letter ‘m’. 3. Write command to display all files having names up to ten characters with second last letter as ‘n’, e.g. intelligent. 4. Write a command to copy the file mars of type exe from the directory ‘space’ of drive U to another directory “universe” in drive S. 5. Write a command to delete the directory as well as the files of the directory ‘world’ on drive E. 6. Write command to display all file names on the disk in drive A and having an extension of no more than two characters.   7. Write command to copy all the files beginning with ‘m’ and whose file names has a ‘txt’ extension from drive A to the ‘\document’ directory on drive C. 8. Write set of commands to create a subdirectory of the root directory called ‘exercise’, and then move into it 9. Perform the following tasks using DOS commands in the DOS sh...

Learn Programming in UNIX

Q: - Write a program to input two numbers and add them?             gedit add.sh             clear             echo “enter two numbers:”             read a             read b             sum=`expr$a+$b`             echo $sum Syntax for if-else:- (1)          if test condition             then                 ---------                 --...

IICS College 15th August Celebration Day

IICS COLLEGE  15th August Celebration Day