Fundamentals of Computer and programming in C

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Constants, Variables, and Data Types
CSci 1130 Intro to Programming in Java
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Structure of a C program
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
The C Character Set: The Characters used to form words, numbers and Expression depends upon the computer on which program runs. Letters. Digits White spaces.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Lecture #5 Introduction to C++
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CSCI 130 Chapter 3. Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
INTRODUCTION TO C C was developed by Dennis Ritchie at Bell laboratory in 1972 It is an upgrade version of languages B and BCPL.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
Chapter2 Constants, Variables, and Data Types. 2.1 Introduction In this chapter, we will discuss –constants (integer, real, character, string, enum),symbolic.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
INTRODUCTION TO ‘C’ PROGRAMMING BY Prof. P. PADMANABHAM M.Tech (AE), M.Tech(CS), Ph.D(CS)-FIETE, FIE Director Academics, Bharat Institute Of Engineering.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Powerpoint Templates Page 1 Programming in C/C++ PS04CINS02.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
MAHENDRAN. Session Objectives Session Objectives  Discuss the Origin of C  Features of C  Characteristics of C  Current Uses of C  “C” Programming.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Lecture 4 Monday Sept 9, Variables and Data Types ►A►A►A►A variable is simply a name given by the programmer that is used to refer to computer storage.
Constants, Data Types and Variables
Introduction to ‘c’ language
Data types Data types Basic types
BASIC ELEMENTS OF A COMPUTER PROGRAM
Wel come.
' C ' PROGRAMMING SRM-MCA.
CMSC 104, Section 4 Richard Chang
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
C++ Basics.
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
C AS A LANGUAGE Interface between computer & human being. ALPHABETS
Chapter 2: Java Fundamentals
Variables in C Topics Naming Variables Declaring Variables
Variables in C Declaring , Naming, and Using Variables.
Chap 2. Identifiers, Keywords, and Types
Module 2 Variables, Data Types and Arithmetic
Lexical Elements & Operators
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Programming Fundamental-1
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Fundamentals of Computer and programming in C Rohit Khokher

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

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 =

Tokens Operators Keywords Identifiers Constants Strings Special symbols +, -, *, /, … Numeric constants like -59.67 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 …

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

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

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

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;

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

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.

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;

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

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.

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;

Programing example # include <stdio.h> void main() { float x, p; double y, q; unsigned k; int m=54321; long int n=1234567890; x = 1.2345678900; y= 9.87654321; 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); }

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