By: Syed Shahrukh Haider

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Advertisements

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Structure of a C program
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
Introduction to C Programming CE Lecture 2 Basics of C programming.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Data types and variables
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Chapter 2 Data Types, Declarations, and Displays
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Variable & Constants. A variable is a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
UniMAP Sem2-08/09 DKT121: Fundamental of Computer Programming1 Introduction to C – Part 2.
C Tokens Identifiers Keywords Constants Operators Special symbols.
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
UNIMAP Sem2-07/08EKT120: Computer Programming1 Week 2 – Introduction to Programming.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
Basics of ‘ C ’ By Gaikwad Varsha P. Asst. Prof. Information Technology Dept. Govt. College of Engg. Aurangabad.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Lecture2.
Bill Tucker Austin Community College COSC 1315
CSCE 206 Structured Programming in C
Chapter 2 Variables.
Chapter Topics The Basics of a C++ Program Data Types
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
User Interaction and Variables
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Revision Lecture
Introduction to C Programming
Basic Elements of C++ Chapter 2.
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,
2.1 Parts of a C++ Program.
Basics of ‘C’.
Beginning C Lecture 2 Lecturer: Dr. Zhao Qinpei
Introduction to C Programming
Chapter 2 Variables.
Chapter 2: Introduction to C++.
Introduction to Java Applications
Primitive Types and Expressions
Module 2 Variables, Data Types and Arithmetic
Chapter 2 Variables.
DATA TYPES There are four basic data types associated with variables:
C Language B. DHIVYA 17PCA140 II MCA.
Getting Started With Coding
Data Types and Arithmetic in C
Presentation transcript:

By: Syed Shahrukh Haider C Building Block By: Syed Shahrukh Haider

Introduction Three importance aspects of any language are the way it stores data, how it accomplished input & output, and the operator it uses to transform and combine data.

Variable A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive

Type of Variable C Sr.No. Type & Description 1 char Typically a single octet(one byte). This is an integer type. 2 int The most natural size of integer for the machine. 3 float A single-precision floating point value. 4 double A double-precision floating point value. 5 void Represents the absence of type.

A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type and contains a list of one or more variables of that type as follows − type variable_list; Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object; and variable_list may consist of one or more identifier names separated by commas. Some valid declarations are shown here − int i, j, k; char c, ch; float f, salary; double d;

type variable_name = value; The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to create variables named i, j and k of type int. Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows − type variable_name = value;

Example of Variable Void main(void){ Int event; char heat; float time; event = 5; heat = ‘C’; time = 27.25; printf(“The winning time in heat %c”, heat); printf(“ of event %d was &f.”, event, time); }

Initializing Variable Void main(void){ Int event = 5; char heat =‘C’; float time = 27.25; printf(“The winning time in heat %c”, heat); printf(“ of event %d was &f.”, event, time); }

Output %c – single character %s – string %d – signed decimal integer Command: Printf(); %c – single character %s – string %d – signed decimal integer %f – floating point [decimal notation] %e – floating point [exponential notation] %g – floating (%f or %e whichever is shorter) %u – unsigned decimal %x – unsigned hexdecimal %o – unsigned octal

Printf() Format String Signal Format Field width Number of digits to right of decimal place Indicated Decimal-format “floating point” % 6 0 . 1 f

Escape Sequences Escape sequences are used in the programming languages C and also in many more languages An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.

Input Void main(void){ Int event; char heat; float time; Command: scanf(); Void main(void){ Int event; char heat; float time; printf (“enter value of: event,heat & time”) scanf(“%d, %c, %f”, &event &heat &time); printf(“The winning time in heat %c”, heat); printf(“ of event %d was &f.”, event, time); } (&) ampersand = act as pointer to variable to used for storing the input

Some other input command getche() getchar() = require [return/enter] key as input get = get value ch = char e= echo the char

Arithemtic Operator + : Addition example: x = x + y - : Subtraction example: x = x - y * : Multiplication example: x = x * y / : Division example: x = x / y % : remainder example: x = x % y

Arithmetic Assignment Operator += : addition assignment operator example: x += y -= : subtraction assignment operator example: x -= y *= : multiplication assignment operator example: x *= y /= : division assignment operator example: x /= y %=: reminder assignment operator example: x %= y

Increment Operator ++ : increment -- : Decrement

Relational Operator < : less than > : greater than == : equal to <= : less than & equal to >= : greater than & equal to != : no equal to

Comment /* Single line or paragraph that one can state during writing code, this will assist programmer comment out coding or some important feature that can help him or some else to understand in future. But these lines will not interfere during compile/build */