Fundamental of C programming. - Ompal Singh

Similar documents
Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

UNIT- 3 Introduction to C++

Data Types and Variables in C language

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Computers Programming Course 5. Iulian Năstac

Preview from Notesale.co.uk Page 6 of 52

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

C - Basic Introduction

Fundamental of Programming (C)

6.096 Introduction to C++ January (IAP) 2009

Work relative to other classes

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

DEPARTMENT OF MATHS, MJ COLLEGE

Fundamentals of Programming

INTRODUCTION 1 AND REVIEW

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

C: How to Program. Week /Mar/05

Basics of Programming

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Basic Elements of C. Staff Incharge: S.Sasirekha

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

A Fast Review of C Essentials Part I

Programming and Data Structures

Chapter 2 - Introduction to C Programming

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Java Notes. 10th ICSE. Saravanan Ganesh

BCA-105 C Language What is C? History of C

Chapter 1 & 2 Introduction to C Language

Introduction to C Language

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

BASIC ELEMENTS OF A COMPUTER PROGRAM

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Information Science 1

BLM2031 Structured Programming. Zeyneb KURT

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

Creating a C++ Program

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Lecture 02 C FUNDAMENTALS

Full file at C How to Program, 6/e Multiple Choice Test Bank

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

Chapter 2. Lexical Elements & Operators

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Operators. Java operators are classified into three categories:

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

UNIT-2 Introduction to C++

C Language, Token, Keywords, Constant, variable

Reserved Words and Identifiers

CSCI 171 Chapter Outlines

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

ANSI C Programming Simple Programs

VARIABLES AND CONSTANTS

Lecture 3. More About C

Lexical Considerations

JAVA Programming Fundamentals

4.1. Structured program development Overview of C language

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

1.1 Introduction to C Language. Department of CSE

Basics of Java Programming

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Basic Types and Formatted I/O

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

Review of the C Programming Language for Principles of Operating Systems

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

THE FUNDAMENTAL DATA TYPES

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Review of the C Programming Language

Objectives. In this chapter, you will:

C Programming Multiple. Choice

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Have the same meaning as variables in algebra Single alphabetic character Each variable needs an identifier that distinguishes it from the others a =

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Computers Programming Course 6. Iulian Năstac

Course Outline Introduction to C-Programming

Programming in C++ 4. The lexical basis of C++

Presented By : Gaurav Juneja

Chapter 3: Operators, Expressions and Type Conversion

Preface. Intended Audience. Limits of This Dictionary. Acknowledgments

Variables and literals

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

Tokens, Expressions and Control Structures

Operators in C. Staff Incharge: S.Sasirekha

Transcription:

Fundamental of C programming - Ompal Singh

HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE UNIVERSITY. IT WAS TOO TURNED OUT TO BE VERY BIG AND DIFFICULT TO LEARN. IN 1967 BCPL(BASIC CPL) AT CAMBRIDGE UNIVERSITY IT WAS TOO SPECIFIC AND MUCH TOO LESS POWERFUL.

IN 1970 B LANGUAGE SIMPLIFICATION TO CPL BY KEN THOMPSON AT AT&T LABS IT WAS TOO SPECIFIC AND LIMITED IN APPLICATION. IN 1972 C DEVELOPED BY Dennis Ritchie AT AT&T LABS. IT WAS TRULY A GENERAL LANGUAGE TO LEARN AND VERY POWERFUL. EASY IN 1972 THE NEXT PHASE OF EVALUATION TO C BY INCORPORATING FEATURES OF OOP REINCARNATING C INTO ITS NEW AVATAR C++.

Characteristics of C We briefly list some of C's characteristics that define the language and also have lead to its popularity as a programming language. Naturally we will be studying many of these aspects throughout the course. Small size Extensive use of function calls Loose typing -- unlike PASCAL Structured language Low level (BitWise) programming readily available Pointer implementation - extensive use of pointers for memory, array, structures and functions.

C has now become a widely used professional language for various reasons. It has high-level constructs. It can handle low-level activities. It produces efficient programs. It can be compiled on a variety of computers. Structured language

FEATURES OF C LANGUAGE C is a machine dependent. C is case sensitive language. It is highly portable language. It has only as few as 32 keywords It has a comprehensive set of operators. Users can create their own functions. C is low level & high level support. It has a large library of functions.

The C Compilation Model

Executing a C program Text Editor C-compiler 010110 100. 01011 101 Linker 00101010. 01010101 machine code of library file C-Runtime Input #include<stdio.h> int main() {. compiles Syntax Errors? prog1.c No Object machine code adds Executable machine code Executes Feeds Runtime or Logic Errors? Output Yes prog1.obj prog1.exe Yes Translators are system software used to convert high-level language program into machinelanguage code. Compiler : Coverts the entire source program at a time into object code file, and saves it in secondary storage permanently. The same object machine code file will be executed several times, whenever needed. Interpreter : Each statement of source program is translated into machine code and executed immediately. Translation and execution of each and every statement is repeated till the end of the program. No object code is saved. Translation is repeated for every execution of the source program.

The Preprocessor The Preprocessor accepts source code as input and is responsible for removing comments interpreting special preprocessor directives denoted by #. For example #include -- includes contents of a named file. Files usually called header files. e.g #include <math.h> -- standard library maths file. #include <stdio.h> -- standard library I/O file #define -- defines a symbolic name or constant. Macro substitution. #define MAX_ARRAY_SIZE 100 C Compiler The C compiler translates source to assembly code. The source code is received from the preprocessor. Assembler The assembler creates object code. On a UNIX system you may see files with a.o suffix (.OBJ on MSDOS) to indicate object code files. Link Editor If a source file references library functions or functions defined in other source files the link editor combines these functions (with main()) to create an executable file.

Structure of C program Documentation Section Linkage Section Definition Section Global Declaration Section Main Function Section Local Declaration Part Executable Code Part Sub Program Section Function1() Function2() FunctionN()

Structure of a C Program Syntax of basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaration section */ /* Function section */ (return type) (function name) (arguments...) void main () { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...)... (return type) (function name n) (arguments...)

How to run a simple c program 1. Copy Turbo c/c++ in computer 2. Open c:\tc\bin\tc.exe 3. A window appears 4. Select File->new to open a new file

Program to print hello 5. Type the following program on editor #include <stdio.h> void main() { printf( hello ); } 6. compile the program by pressing ALT+F9 7. Run the program by pressing CTRL +F9

CHARACTER SET Letters A Z or a z. Digits 0 9. Special Symbols (all the special symbols present on the keyboard) White spaces Blanks space, horizontal tab, carriage return, new line, from feed.

C tokens: C tokens are the basic buildings blocks in C language which are constructed together to write a C program. Each and every smallest individual units in a C program are known as C tokens. C tokens are of six types. They are, Keywords Identifiers (eg: int, while), (eg: main, total), Constants (eg: 10, 20), Strings Special symbols (eg: (), {}), (eg: total, hello ), Operators (eg: +, /,-,*)

USING COMMENTS It is a good programming practice to place some comments in the code to help the reader understand the code clearly. Comments are just a way of explaining what a program does. It is merely an internal program documentation. The compiler ignores the comments when forming the object file. This means that the comments are non-executable statements. C supports two types of commenting. // is used to comment a single statement. This is known as a line comment. A line comment can be placed anywhere on the line and it does not require to be specifically ended as the end of the line automatically ends the line. /* is used to comment multiple statements. A /* is ended with */ and all statements that lie within these characters are commented.

Keywords Keywords are words, which have special meaning for the C compiler. Keywords are also sometimes known as reserved words. Following is a list of keywords C

IDENTIFIERS Identifiers are names given to program elements such as variables, arrays and functions. Rules for forming identifier name it cannot include any special characters or punctuation marks (like #, $, ^,?,., etc) except the underscore"_". There cannot be two successive underscores Keywords cannot be used as identifiers The names are case sensitive. So, example, FIRST is different from first and First. It must begin with an alphabet or an underscore. It can be of any reasonable length. Though it should not contain more than 31 characters. No blank space between the name of identifiers Example: roll_number, marks, name, emp_number, basic_pay, HRA, DA, dept_code

Variable Variable is a name of memory location where we can store any data. It can store only single data (Latest data) at a time. In C, a variable must be declared before it can be used. Variables can be declared at the start of any block of code, but most are found at the start of each function. A declaration begins with the type, followed by the name of one or more variables. For example, DataType Name_of_Variable_Name; int a,b,c;

VARIABLES IN C A variable is defined as a meaningful name given to the data storage location in computer memory. When using a variable, we actually refer to address of the memory where the data is stored. C language supports two basic kinds of variables. Numeric variables can be used to store either integer values or floating point values. While an integer value is a whole numbers without a fraction part or decimal point, a floating point number, can have a decimal point in them. Numeric values may also be associated with modifiers like short, long, signed and unsigned. By default, C automatically a numeric variable signed.. To declare a variable specify data type of the variable followed by its name. Variable names should always be meaningful and must reflect the purpose of their usage in the program. Variable declaration always ends with a semicolon. Example, int emp_num; float salary; char grade; double balance_amount; unsigned short int acc_no; Numeric Variable Variables Character Variables

Variable names- Rules it cannot include any special characters or punctuation marks (like #, $, ^,?,., etc) except the underscore"_". There cannot be two successive underscores Keywords cannot be used as identifiers The names are case sensitive. So, example, FIRST is different from first and First. It must begin with an alphabet or an underscore. It can be of any reasonable length. Though it should not contain more than 31 characters. No blank space between the name of variable

Local Variables Local variables are declared within the body of a function, and can only be used within that function only. Global Variable A global variable declaration looks normal, but is located outside any of the program's functions. This is usually done at the beginning of the program file, but after preprocessor directives. The variable is not declared again in the body of the functions which access it. Syntex of local variable: Syntax of global variable: #include<stdio.h> int a,b; void main( ) void main() { { int a,b,c; } } fun() Fun() { { } }

CONSTANTS Constants are identifiers whose value does not change. Constants are used to define fixed values like PI or the charge on an electron so that their value does not get changed in the program even by mistake. To declare a constant, precede the normal variable declaration with const keyword and assign it a value. For example, const float pi = 3.14; Another way to designate a constant is to use the pre-processor command define. #define PI 3.14159 When the preprocessor reformats the program to be compiled by the compiler, it replaces each defined name with its corresponding value wherever it is found in the source program. Hence, it just works like the Find and Replace command available in a text editor. Rules that needs to be applied to a #define statement which defines a constant. Constant names are usually written in capital letters to visually distinguish them from other variable names which are normally written in lower case characters. Note that this is just a convention and not a rule. No blank spaces are permitted in between the # symbol and define keyword Blank space must be used between #define and constant name and between constant name and constant value #define is a pre-processor compiler directive and not a statement. Therefore, it does not end with a semi-colon.

Constant Constant is a special types of variable which can not be changed at the time of execution. Syntax: syntax: const int a=20; Types of constant: Character Constant. Integer Constant. Real Constant. String Constant.

CHARACTER CONSTANTS The maximum length of a character constant is one character. Ex : a is a character constant.

INTEGER CONSTANT An integer constant refers to a sequence of digits. There are three types of integers in C language : Decimal. Octal. Hexadecimal. EX : 1,56,7657, - 34 etc.

Real Or Floating Point Constants A number with a decimal point and an optional preceding sign represents a real constant. Ex : 34.8, -655.33,.2, -.56, 7.

String Constants A string constant is a sequence of one or more characters enclosed within a pair of double quotes ( ) if a single character is enclosed within a pair E. G. Welcome to c programming \n.

Qualifiers A type qualifier is used to refine the declaration of a variable, a function, and parameters, by specifying whether: The value of a variable can be changed. The value of a variable must always be read from memory rather than from a register Standard C language recognizes the following two qualifiers: 1.const 2.volatile The const qualifier is used to tell C that the variable value can not change after initialisation. const float pi=3.14159; Now pi cannot be changed at a later time within the program. Another way to define constants is with the #define preprocessor which has the advantage that it does not use any storage The volatile qualifier declares a data type that can have its value changed in ways outside the control or detection of the compiler (such as a variable updated by the system clock or by another program). This prevents the compiler from optimizing code referring to the object by storing the object's value in a register and re-reading it from there, rather than from memory, where it may have changed. You will use this qualifier once you will become expert in "C". So for now just proceed.

Input and Output Input scanf( %d,&a); Gets an integer value from the user and stores it under the name a Output printf( %d,a) Prints the value present in variable a on the screen

Formatted Printing with printf Escape Sequence Effect \a Beep sound \b Backspace \f Formfeed (for printing) \n New line \r Carriage return \t Tab \v Vertical tab \\ Backslash \ sign \o Octal decimal \x Hexadecimal \O NULL

DATA TYPES C data types are defined as the data storage format that a variable can store a data to perform a specific operation. Data types are used to define a variable before to use in a program. Size of variable, constant and array are determined by data types.

Different types of data types 1.Primary data types( integer, float, character, double) 2.Derived data types(array,structure) 3.User define data types a. Typedef b. Enum

Primary data type All C Compilers accept the following fundamental data types 1.Integer int %d 2.Character char %c 3.Floating Point float %f 4.Double double %lf

DATA TYPE RANGE OF VALUES char -128 to 127 Int -32768 to +32767 Float 3.4 e-38 to 3.4 e+38 double 1.7 e-308 to 1.7 e+308

Modifiers in C: The amount of memory space to be allocated for a variable is derived by modifiers. Modifiers are prefixed with basic data types to modify (either increase or decrease) the amount of storage space allocated to a variable. For example, storage space for int data type is 4 byte for 32 bit processor. We can increase the range by using long int which is 8 byte. We can decrease the range by using short int which is 2 byte. There are 4 modifiers available in C language. They are, short long signed unsigned

DATA TYPE SIZE IN BYTES RANGE char 1-128 to 127 unsigned char 1 0 to 255 signed char 1-128 to 127 int 2-32768 to 32767 unsigned int 2 0 to 65535 signed short int 2-32768 to 32767 signed int 2-32768 to 32767 short int 2-32768 to 32767 unsigned short int long int unsigned long int signed long int 2 4 4 4 0 to 65535-2147483648 to 2147483647 0 to 4294967295-2147483648 to 2147483647 float 4 3.4E-38 to 3.4E+38 double 8 1.7E-308 to 1.7E+308 long double 10 3.4E-4932 to 1.1E+4932 DATA TYPES IN C

TYPE SIZE (Bits) Range Char or Signed Char 8-128 to 127 Unsigned Char 8 0 to 255 Int or Signed int 16-32768 to 32767 Unsigned int 16 0 to 65535 Short int or Signed short int 8-128 to 127 Unsigned short int 8 0 to 255 Long int or signed long int 2147483647 32-2147483648 to Unsigned long int 32 0 to 4294967295 Float 32 3.4 e-38 to 3.4 e+38 Double 64 1.7e-308 to 1.7e+308 Long Double 80 3.4 e-4932 to 3.4 e+4932

OPERATORS IN C C language supports a lot of operators to be used in expressions. These operators can be categorized into the following major groups: Arithmetic operators Relational Operators Equality Operators Logical Operators Unary Operators Conditional Operators Bitwise Operators Assignment operators Comma Operator Sizeof Operator OPERATION OPERATOR SYNTAX COMMENT RESULT ARITHMETIC OPERATORS Multiply * a * b result = a * b 27 Divide / a / b result = a / b 3 Addition + a + b result = a + b 12 Subtraction - a - b result = a b 6 Modulus % a % b result = a % b 0

RELATIONAL OPERATORS Also known as a comparison operator, it is an operator that compares two values. Expressions that contain relational operators are called relational expressions. Relational operators return true or false value, depending on whether the conditional relationship between OPERATOR the two operands holds MEANING or not. EXAMPLE < LESS THAN 3 < 5 GIVES 1 > GREATER THAN 7 > 9 GIVES 0 >= LESS THAN OR EQUAL TO 100 >= 100 GIVES 1 <= GREATER THAN EQUAL TO 50 >=100 GIVES 0 EQUALITY OPERATORS C language supports two kinds of equality operators to compare their operands for strict equality or inequality. They are equal to (==) and not equal to (!=) operator. The equality operators have lower precedence than the relational operators. OPERATOR MEANING == RETURNS 1 IF BOTH OPERANDS ARE EQUAL, 0 OTHERWISE!= RETURNS 1 IF OPERANDS DO NOT HAVE THE SAME VALUE, 0 OTHERWISE

LOGICAL OPERATORS C language supports three logical operators. They are- Logical AND (&&), Logical OR ( ) and Logical NOT (!). As in case of arithmetic expressions, the logical expressions are evaluated from left to right. A B A &&B 0 0 0 0 1 0 1 0 0 1 1 1 A B A B 0 0 0 0 1 1 1 0 1 1 1 1 A! A 0 1 1 0 UNARY OPERATORS(Increment and Decrement) Unary operators act on single operands. C language supports three unary operators. They are unary minus, increment and decrement operators. When an operand is preceded by a minus sign, the unary operator negates its value. The increment operator is a unary operator that increases the value of its operand by 1. Similarly, the decrement operator decreases the value of its operand by 1. For example, int x = 10, y; y = x++; is equivalent to writing y = x; x = x + 1; whereas, y = ++x; is equivalent to writing x = x + 1; y = x;

CONDITIONAL OPERATOR The conditional operator operator (?:) is just like an if.. else statement that can be written within expressions. The syntax of the conditional operator is exp1? exp2 : exp3 Here, exp1 is evaluated first. If it is true then exp2 is evaluated and becomes the result of the expression, otherwise exp3 is evaluated and becomes the result of the expression. For example, large = ( a > b)? a : b Conditional operators make the program code more compact, more readable, and safer to use as it is easier both to check and guarantee that the arguments that are used for evaluation. Conditional operator is also known as ternary operator as it is neither a unary nor a binary operator; it takes three operands.

BITWISE OPERATORS Bitwise operators perform operations at bit level. These operators include: bitwise AND, bitwise OR, bitwise XOR and shift operators. The bitwise AND operator (&) is a small version of the boolean AND (&&) as it performs operation on bits instead of bytes, chars, integers, etc. The bitwise OR operator ( ) is a small version of the boolean OR ( ) as it performs operation on bits instead of bytes, chars, integers, etc. The bitwise NOT (~), or complement, is a unary operation that performs logical negation on each bit of the operand. By performing negation of each bit, it actually produces the ones' complement of the given binary value. The bitwise XOR operator (^) performs operation on individual bits of the operands. The result of XOR operation is shown in the table BITWISE SHIFT OPERATORS In bitwise shift operations, the digits are moved, or shifted, to the left or right. The CPU registers have a fixed number of available bits for storing numerals, so when we perform shift operations; some bits will be "shifted out" of the register at one end, while the same number of bits are "shifted in" from the other end. In a left arithmetic shift, zeros are shifted in on the right. For example; unsigned int x = 11000101; Then x << 2 = 00010100 If a right arithmetic shift is performed on an unsigned integer then zeros are shifted on the left. unsigned int x = 11000101; A B A ^ B 0 0 0 0 1 1 1 0 1 1 1 0

ASSIGNMENT OPERATORS The assignment operator is responsible for assigning values to the variables. While the equal sign (=) is the fundamental assignment operator, C also supports other assignment operators that provide shorthand ways to represent common variable assignments. They are shown in the table. OPERATOR SYNTAX EQUIVALENT TO /= variable /= expression variable = variable / expression \= variable \= expression variable = variable \ expression *= variable *= expression variable = variable * expression += variable += expression variable = variable + expression -= variable -= expression variable = variable - expression &= variable &= expression variable = variable & expression ^= variable ^= expression variable = variable ^ expression <<= variable <<= amount variable = variable << amount >>= variable >>= amount variable = variable >> amount

COMMA OPERATOR The comma operator in C takes two operands. It works by evaluating the first and discarding its value, and then evaluates the second and returns the value as the result of the expression. Comma separated operands when chained together are evaluated in left-to-right sequence with the right-most value yielding the result of the expression. Among all the operators, the comma operator has the lowest precedence. For example, int a=2, b=3, x=0; x = (++a, b+=a); Now, the value of x = 6. SIZEOF OPERATOR sizeof is a unary operator used to calculate the sizes of data types. It can be applied to all data types. The operator returns the size of the variable, data type or expression in bytes. 'sizeof' operator is used to determine the amount of memory space that the variable/expression/data type will take. For example, sizeof(char) returns 1, that is the size of a character data type. If we have, int a = 10; unsigned int result; result = sizeof(a); then result = 2,

TYPE CONVERSION AND TYPE CASTING Type conversion and type casting of variables refers to changing a variable of one data type into another. While type conversion is done implicitly, casting has to be done explicitly by the programmer. We will discuss both of them here. Type conversion is done when the expression has variables of different data types. So to evaluate the expression, the data type is promoted from lower to higher level where the hierarchy of data types can be given as: double, float, long, int, short and char. For example, type conversion is automatically done when we assign an integer value to a floating point variable. For ex, float x; int y = 3; x = y; Now, x = 3.0, Type casting is also known as forced conversion. It is done when the value of a higher data type has to be converted in to the value of a lower data type. For example, we need to explicitly type cast an integer variable into a floating point variable. float salary = 10000.00; int sal; sal = (int) salary; Typecasting can be done by placing the destination data type in parentheses followed by the variable name that has to be converted.

Specifier Meaning %c Print a character %d Print a Integer %i Print a Integer %e Print float value in exponential form. %f Print float value %g Print using %e or %f whichever is smaller %o Print actual value %s Print a string %x Print a hexadecimal integer (Unsigned) using lower case a F %X Print a hexadecimal integer (Unsigned) using upper case A F %a Print a unsigned integer. %p Print a pointer value %hx hex short %lo octal long %ld long unsigned integer.

Evaluation of Expression Expression refers to anything that evaluates to a numeric value. Order of Precedence Example () Highest z-(a*b/2)+w*y!, unary +, - 5-(3*9/2)+2*-5 *, /, % 5-(27/2)+-10 binary +, - 5-13+-10 <,<=,>,>= -8+-10 ==,!= -18 && Lowest

User define data types: Enumeration Type def

User define data types: Enumeration type allows programmer to define their own data type. Keyword enum is used to defined enumerated data type. Syntax: enum type_name{ value1,value2,...,valuen }; Here, type_name is the name of enumerated data type or tag. And value1, value2,...,valuen are values of type type_name. By default, value1 will be equal to 0, value2 will be 1 and so on but, the programmer can change the default value.

Declaration of emun: enum boolean{ false; true; }; enum boolean check; Here, a variable check is declared which is of type enum boolean. Example. #include<stdio.h> enum week{ sunday, monday, tuesday, wednesday, thursday, friday, saturday}; int main(){ enum week today; today=wednesday; printf("%d day",today+1); return 0; }

Typedef C programming language provides a keyword called typedef, which you can use to give a type a new name. You can use typedef to give a name to user defined data type as well.

Typedef #include<stdio.h> void main() { typedef int num; num a,b,c; printf("enter the number ); scanf( %d%d,&a,&b); c=a+b; printf( %d,c); }