Introduction

Computer is a machine that can perform computation

  1. Input:User gives a set of Input
  2. Processing:Input data is processed by a well defined and finite sequence of steps
  3. Output:Some data available from processing step and output to the user
A Computer (Level 0 Version)
Figure 2.0:

Programming and Software

Computer needs to be programmed to do such tasks:-

Programming: is the process of writing instructions in a language that can be understood by the computer so that a desired task can be performed by it
Program: sequence of instructions to do a task,computer processes the instructions sequentially one after the other
Software: programs for doing tasks on computers

Structure Of C Program

Variables

Variables in Memory

Figure 2.5
Figure 2.2
Figure 2.3
Figure 2.4
Variables in memory

How to give Names of Variable

  1. Sequence of letters and digits
  2. First character must be a letter or _
  3. No special characters other than _
  4. No blank in between
  5. Names are case-sensitive (max and Max are two different names)
    • Examples of valid names:
      • rank1, MAX, max, Min, class_rank
    • Examples of invalid names:
      • 's ,fact rec,2sqroot,class?rank

Constants

        Illustration 2.3
        #include<stdio.h >
        void main()
        {
          int x;
          int y;
          x=1;
          y=3;
          printf("x = %d, y= %d\n", x, y);
        }
    
        Output:
        x=1, y=3
    

C Keywords

Input:Scanf function

Commonly used conversion characters

  1. c :for char type variable
  2. d :for int type variable
  3. f :for float type variable
  4. lf :for double type variable
    • Examples:
    • scanf("%d", &size) ;
    • scanf("%c", nextchar) ;
    • scanf("%f", &length) ;
    • scanf("%d%d", &a, &b);

Reading a single character

Data types

Some typical sizes (some of these can vary depending on type of machine)

Data Types range Table

Chapter 2 Quiz

1.How much memory Size takes char,int,float :& double datatypes in memory
2. scanf() is a predefined function in which header file?
3.What is the Range of Char Data Types
4.What outputs does it generates:printf ( "%d" , printf ( "helloWorld" ) );
5.Which of the data types has the size that is variable?
Home Page
Top of Page
Go Next
Go Next