Department of Electronic & Electrical Engineering Statements Blocks{} Semicolons ; Variables Names keywords Scope.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Chapter 7: User-Defined Functions II
Introduction to C Programming
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Structure of a C program
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
1 Modularity In “C”. 2 General Syntax data_type function_Name (parameter list) { … return expression; // return output } Body of the function is a compound.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
18-2 Understand “Scope” of an Identifier Know the Storage Classes of variables and functions Related Chapter: ABC 5.10, 5.11.
The C Character Set: The Characters used to form words, numbers and Expression depends upon the computer on which program runs. Letters. Digits White spaces.
H.Melikian Introduction on C C is a high-level programming language that forms the basis to other programming languages such as C++, Perl and Java. It.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Fundamental Programming: Fundamental Programming Introduction to C++
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
1 Loops II. 2 Recall the while Loop int sum = 0; int i = 1;... /* Sum the integers 1 to 10 */ while ( i
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Minimal standard C program int main(void) { return 0 ; }
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 2. Program Construction in Java. 01 Java basics.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
Windows Programming Lecture 03. Pointers and Arrays.
Numbers in ‘C’ Two general categories: Integers Floats
Last week: We talked about: History of C Compiler for C programming
Val Manes Department of Math & Computer Science
Chapter 7: User-Defined Functions II
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Objectives Identify the built-in data types in C++
trigraph ??= is for # ??( is for [ ??< is for { ??! is for |
Introduction to C++.
Programming Fundamentals Lecture #7 Functions
Chapter 2: Introduction to C++
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Classes and Objects.
Chapter 2: Introduction to C++.
are shown in the COMMENTS example.
WEEK-2.
ECE 103 Engineering Programming Chapter 12 More C Statements
Fundamental Programming
Lexical Elements & Operators
Variables in C Topics Naming Variables Declaring Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Department of Electronic & Electrical Engineering Statements Blocks{} Semicolons ; Variables Names keywords Scope

Department of Electronic & Electrical Engineering int x=5; int y=6; int z; z=x*2; x = y + z; printf("X"); Statements and semi colons. A statement is the smallest standalone element of a program. In C a statement must be terminated with a semicolon. examples: C ignores new lines and spaces (Very bad style but legal) declarations assignments function calls

Department of Electronic & Electrical Engineering Blocks and {} Curly brackets {} can be used to form a CODE BLOCK. Blocks are use to: Create a compound statement. Contain the body of a function. Blocks can be nested. { { } { } }

Department of Electronic & Electrical Engineering Compound Statements. if ( x>y) { printf(" x>y \n"); x=y; } Note that and if acts on a single statement if ( x>y) printf(" x>y \n"); x=y; /* not part of the if. Always executed. */

Department of Electronic & Electrical Engineering Function body void foo(int x, int y) { if ( x>y) { printf(" x>y " \n); x=y; } function body More about functions later...

Department of Electronic & Electrical Engineering Comments, Types Variables and Constants. { /* Declare some variables */ /*(must be at the start of a block) */ int i; float x,y,z; char c; /* Some assignment statement */ i=5; /* 5 is an integer constant */ x=2.0; /* 2.0 is a floating point constant */ y=3.0; c='X'; /* single quotes for a char */ z=x*y*4.0; /* x*y*4.0 is an expression */ } Comments delimited by /*.... */ Type Name Assignments Expressions

Department of Electronic & Electrical Engineering Demo: Run this with the debugger. int main() { /* Declare some variables */ /*(must be at the start of a block) */ int i; float x,y,z; char c; /* Some assignment statement */ i=5; /* 5 is an integer constant */ x=2.0; /* 2.0 is a float constant */ y=3.0; c='X'; /* single quotes for a char */ z=x*y*4.0; /* x*y*4.0 is an expression */ }

Department of Electronic & Electrical Engineering Examining variables using the debugger. Run the previous code to the i=5 line using the debugger A window appears showing the values of your variables. Note the variables are random values (whatever is in the memory). Step through the code and watch the values change!

Department of Electronic & Electrical Engineering Names for Variables and Functions In C you must declare variables/functions before they used. e.g. { int x; float z; ……. x and z are names.

Department of Electronic & Electrical Engineering Rules for Variable names Rules for constructing variable names Characters can be alphabets (a-z,A-Z), digits (0-9) and underscores ( _ ). Start with alphabet or underscore (not a digit). C keywords are not allow e.g. if for do int...

Department of Electronic & Electrical Engineering These keywords can not be used as names. All the keywords of the C language!

Department of Electronic & Electrical Engineering { int x; int z=4; x=3; { int x; /* a new variable */ int y=z; x=4; } /* what is x here ? */ y=5; } Declaring variables, nested blocks, scope. Hides the previous x BAD IDEA compile time error ! y does not exists here. The part of a program in which you can use a variable is called it's scope. you can see variables declared in a containing block.

Department of Electronic & Electrical Engineering Scope. Global: Variables declared outside functions can be seen every where (unless hidden by name reuse) Local: Variables declared within curly brackets are not visible outside the block. int x; /* global */ void main() { int x; /* local */ }

Department of Electronic & Electrical Engineering Statements smallest stand alone part of your code. Blocks{} create a compound statement from a number of other statements. Semicolons ; marks end of statements

Department of Electronic & Electrical Engineering Names labels for variables and functions Scope extent of a program in which a variable can be seen.