Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Computer and programming in C

Similar presentations


Presentation on theme: "Fundamentals of Computer and programming in C"— Presentation transcript:

1 Fundamentals of Computer and programming in C
Rohit Khokher

2 Programming in C Data Types History of C Constants Importance of C
Symbolic class Variables Declarations A variable as a constant A variable as volatile Storage class Data overflow & underflow History of C Importance of C Structure of C Programs Character Set, tokens, key words & identifiers. Self study Self study Already covered

3 Character Set, tokens, key words & identifiers.
Letters (Uppercase A-Z, Lowercase a-z) Digits 0-9 Special characters Comma Period Semicolon Colon Question mark Apostrophe Quotation mark Exclamation mark Vertical bar Slash Backlash Tilde Under score Dollar , . ; : ? ! | / \ ~ _ $ Percent sign Caret Asterisks Minus sign Plus sign Less than Greater than Left parenthesis Right parenthesis Left brace Right brace Number sign Left bracket Right bracket % ^ * - + < > ( ) { } # [ ] Equal WHITE SPACES Blank space Horizontal tab Carriage Return New line Form feed =

4 Tokens Operators Keywords Identifiers Constants Strings
Special symbols +, -, *, /, … Numeric constants like Character constants like “Year 2010” “Year 2010” Variable names symbolizing memory addresses. Rules for creating identifiers The first character must be an alphabet or underscore. Must consists of letters, digits, or underscore May have 256 characters but only the first 31 characters are important Should be a keyword Should contain white spaces [. ]. {. }. (. … Words with fixed meaning. Must be written in lower case. Example: main, int, float …

5 Tokens key words or reserve words (Prepare a list of ANSI C Key words)
Constants Numeric Character Single String Integer Real Backslash ‘\a’ bell sound ‘\f’ backspace ‘\n’ new line ‘\t’ horizontal tab ….. Decimal, Octal and Hexadecimal

6 Example Integer Values 3276 -32768 -32759
#include <stdio.h> void main { printf (“Integer values \n\n”); printf (“%d %d %d \n”, 32767, , ); printf (“\n”); } Output Integer Values Why negative?

7 void Data Types Primary Data Types integer Character floating Point
Signed -128 to 127 Unsigned 0 to 255 floating Point signed unsigned Int short int long int unsigned int unsigned short int unsigned long int float Double Long double Exercise: Find the size and range of each data type

8 Variable Declaration Data Type Keyword Declaration in C
Character (8 bits) char char a, b, c; Unsigned Character unsigned char unsigned char a, b, c; Signed Character signed char signed char a, b, c; Integer (16 bits) int int x, y, z; Short Integer (8 bits) short int short int x, y, z; Long Integer (32 bits) long int long int x, y, z; Real (32 bits) float Float x,y,z; Real (64 bits) double double x, y, z; Real (89 bits) long double Long double x, y, z;

9 Example # include <stdio.h> float x, y; int code;
Data Segment # include <stdio.h> float x, y; int code; short int count; long int amount; double deviation; unsigned n; char c; /* */ Main () { } x: 4 Bytes y; 4 Bytes code; 2 Byte count; 1 Bytes amount; 4 Bytes deviation; 8 Bytes n; 2 Bytes c; 1 Byte

10 User defined Data types
typedef User can define type using typedef feature. Example typedef int unit; typedef float marks; Unit symbolizes int and marks float. unit x, y, z; means x, y and z are integer type. float a, b, c; means a, b, and c are float type.

11 User defined data type enum (enumerated type) Example
enum identifier ( value1, value2, …, valuen) Example Definition enum day (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); Variable Declaration enum day week_st, week_end; These declaration day week_st and week_end can take values in (Monday to Sunday) and we can use them as week_st = Monday; week_end=Friday;

12 Storage Class Location and visibility of variables.
# include <stdio.h> float x, y; void main () { int i; float b; - - - functionx (); } float functionx (); float s; Data segment Global x, y are visible to Main and functionx x y i b i s Local to main The variables i and b are visible to main only Local functionx The variables i and s are visible to functionx only

13 Storage class and their meaning
auto : known within the function it is declared. static: a local variable that retains its velue even after the control is transferred to calling program. extern: global variable known to all functions. register: a local variable that is stored in a register.

14 Assigning values to variables
Assignment statement Assignment statement is defined as identifier = expression where expression give a value. Example fee = 20.5; rent = 56; expense = fee + rent;

15 Programing example # include <stdio.h> void main() { float x, p;
double y, q; unsigned k; int m=54321; long int n= ; x = ; y= ; k= 54321; P=q=1.0; printf (“ m = %d \n”, m); printf (“ n = %ld \n”, n); printf (“ x = %.121f \n”, x); printf (“ x = %f \n”, x); printf (“ y = %.121f \n”, y); printf (“ y = %f \n”, y); printf (“ k = %u p = %f q = %.121f \n”, k,p,q); }

16 Defining Synbolic Constants
#define directives #define PI 3.14 #define PASS_MARK 50 #define MAX = 100 #define STRENGTH 200


Download ppt "Fundamentals of Computer and programming in C"

Similar presentations


Ads by Google