Fundamental of C programming. - Ompal Singh
|
|
- Phoebe Lucas
- 5 years ago
- Views:
Transcription
1 Fundamental of C programming - Ompal Singh
2 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.
3 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++.
4 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.
5 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
6 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.
7 The C Compilation Model
8 Executing a C program Text Editor C-compiler Linker 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.
9 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.
10 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()
11 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...)
12 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
13 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
14 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.
15 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: +, /,-,*)
16 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.
17 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
18 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
19 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;
20 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
21 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
22 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() { { } }
23 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 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.
24 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.
25 CHARACTER CONSTANTS The maximum length of a character constant is one character. Ex : a is a character constant.
26 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.
27 Real Or Floating Point Constants A number with a decimal point and an optional preceding sign represents a real constant. Ex : 34.8, ,.2, -.56, 7.
28 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.
29 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= ; 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.
30 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
31 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
32 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.
33 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
34 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
35 DATA TYPE RANGE OF VALUES char -128 to 127 Int to Float 3.4 e-38 to 3.4 e+38 double 1.7 e-308 to 1.7 e+308
36 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
37 DATA TYPE SIZE IN BYTES RANGE char to 127 unsigned char 1 0 to 255 signed char to 127 int to unsigned int 2 0 to signed short int to signed int to short int to unsigned short int long int unsigned long int signed long int to to to to float 4 3.4E-38 to 3.4E+38 double 8 1.7E-308 to 1.7E+308 long double E-4932 to 1.1E+4932 DATA TYPES IN C
38 TYPE SIZE (Bits) Range Char or Signed Char to 127 Unsigned Char 8 0 to 255 Int or Signed int to Unsigned int 16 0 to Short int or Signed short int to 127 Unsigned short int 8 0 to 255 Long int or signed long int to Unsigned long int 32 0 to Float e-38 to 3.4 e+38 Double e-308 to 1.7e+308 Long Double e-4932 to 3.4 e+4932
39 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
40 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
41 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 A B A B A! A 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;
42 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.
43 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 = ; Then x << 2 = If a right arithmetic shift is performed on an unsigned integer then zeros are shifted on the left. unsigned int x = ; A B A ^ B
44 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
45 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,
46 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 = ; 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.
47 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.
48 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 +, <,<=,>,>= ==,!= -18 && Lowest
49 User define data types: Enumeration Type def
50 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.
51 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; }
52 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.
53 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); }
Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationData Types and Variables in C language
Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are
More informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationPreview from Notesale.co.uk Page 6 of 52
Binary System: The information, which it is stored or manipulated by the computer memory it will be done in binary mode. RAM: This is also called as real memory, physical memory or simply memory. In order
More informationProgramming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]
Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students
More informationC - Basic Introduction
C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationWork relative to other classes
Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationINTRODUCTION 1 AND REVIEW
INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.
More informationProgramming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan
Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More informationOverview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O
Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationBasics of Programming
Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationBasic Elements of C. Staff Incharge: S.Sasirekha
Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
More informationBCA-105 C Language What is C? History of C
C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is
More informationChapter 1 & 2 Introduction to C Language
1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History
More informationIntroduction to C Language
Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationUNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationIECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.
Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into
More informationPART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.
Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationP.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)
FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationInformation Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationBLM2031 Structured Programming. Zeyneb KURT
BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help
More informationLESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long
LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be
More informationCreating a C++ Program
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. 1 Creating a C++ Program created using an
More informationIntroduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE
Introduction to C programming By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE Classification of Software Computer Software System Software Application Software Growth of Programming Languages History
More informationJava enum, casts, and others (Select portions of Chapters 4 & 5)
Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationLecture 02 C FUNDAMENTALS
Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationIntro to Computer Programming (ICP) Rab Nawaz Jadoon
Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities
INTERNAL ASSESSMENT TEST 1 SOLUTION PART 1 1 a Define algorithm. Write an algorithm to find sum and average of three numbers. 4 An Algorithm is a step by step procedure to solve a given problem in finite
More informationChapter 2. Lexical Elements & Operators
Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System
More informationA complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can
More informationUNIT-2 Introduction to C++
UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some
More informationC Language, Token, Keywords, Constant, variable
C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C
More informationReserved Words and Identifiers
1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationC++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal
TOKENS C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal Tab, Vertical tab, Carriage Return. Other Characters:-
More informationANSI C Programming Simple Programs
ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double
More informationVARIABLES AND CONSTANTS
UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More information4.1. Structured program development Overview of C language
4.1. Structured program development 4.2. Data types 4.3. Operators 4.4. Expressions 4.5. Control flow 4.6. Arrays and Pointers 4.7. Functions 4.8. Input output statements 4.9. storage classes. UNIT IV
More information9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C
Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationXC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.
XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage
More information1.1 Introduction to C Language. Department of CSE
1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationBasic Types and Formatted I/O
Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but
More informationIntroduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,
More informationThe component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science
The component base of C language Nguyễn Dũng Faculty of IT Hue College of Science Content A brief history of C Standard of C Characteristics of C The C compilation model Character set and keyword Data
More informationReview of the C Programming Language for Principles of Operating Systems
Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More informationThe C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationTHE FUNDAMENTAL DATA TYPES
THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include
More informationSEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010
SEQUENTIAL STRUCTURE Erkut ERDEM Hacettepe University October 2010 History of C C Developed by by Denis M. Ritchie at AT&T Bell Labs from two previous programming languages, BCPL and B Used to develop
More informationC++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.
EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationC Programming Multiple. Choice
C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationHave the same meaning as variables in algebra Single alphabetic character Each variable needs an identifier that distinguishes it from the others a =
Morteza Noferesti Have the same meaning as variables in algebra Single alphabetic character Each variable needs an identifier that distinguishes it from the others a = 5 x = a + b valid identifier in C
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationComputers Programming Course 6. Iulian Năstac
Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap
More informationCourse Outline Introduction to C-Programming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
More informationPresented By : Gaurav Juneja
Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationPreface. Intended Audience. Limits of This Dictionary. Acknowledgments
Preface There are many C books on the market, covering a broad range of applications and platforms, and each comes with some form of cross-reference index. However, the art of indexing a book is quite
More informationVariables and literals
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More information>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.
>B
More informationC Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach
C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More information