1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic www.tenouk.comwww.tenouk.com, © In this session we will.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

C++ Basics Variables, Identifiers, Assignments, Input/Output.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
Structure of a C program
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Introduction Computer program: an ordered sequence of instructions whose objective is to accomplish a task. Programming: process of planning and creating.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
The Java Programming Language
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.
CPS120: Introduction to Computer Science
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Introduction to Programming
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Numbers in ‘C’ Two general categories: Integers Floats
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Variables, Identifiers, Assignments, Input/Output
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Basics (Variables, Assignments, I/O)
Chapter 1.2 Introduction to C++ Programming
Data types Data types Basic types
LESSON 3 IO, Variables and Operators
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
Introduction to the C Language
CMSC 104, Section 4 Richard Chang
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Basics (Variables, Assignments, I/O)
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
C++ Basics.
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
Chapter 1: Computer Systems
Introduction to C Programming
Govt. Polytechnic,Dhangar
Variables, Identifiers, Assignments, Input/Output
Variables in C Topics Naming Variables Declaring Variables
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Introduction to C++.
WEEK-2.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Chap 2. Identifiers, Keywords, and Types
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic © In this session we will cover the following sub-topics: 1/16

C IDENTIFIERS 1.Is a unique name that simply references to memory locations, which can hold values (data). 2.Identifiers give unique names to various objects in a program. 3.Are formed by combining letters (both upper and lowercase), digits (0–9) and underscore ( _ ). 4.Rules for identifier naming are: a)The first character of an identifier must be a letter (non-digit) including underscore ( _ ). b)The blank or white space character is not permitted in an identifier. Space, tab, linefeed, carriage-return, formfeed, vertical-tab, and newline characters are "white-space characters“ - they serve the same purpose as the spaces between words and lines on a printed page. c)Can be any length but implementation dependent. d)Reserved words/keywords cannot be used. © 2/16

C IDENTIFIERS Examples: variable names CorrectWrong secondName2ndName /* starts with a digit */ _addNumber%calculateSum /* contains invalid character */ charAndNumchar /* reserved word */ annual_rateannual rate /* contains a space */ stage4markmy\nName /* contains new line character, \n */ © 3/16

C VARIABLES  are named blocks of memory & is any valid identifier.  Have two properties in syntax: name — a unique identifier & type — what kind of value is stored.  It is identifier, that value may change during the program execution.  Every variable stored in the computer’s memory has a name, a value and a type. © 4/16

C VARIABLES  More examples CorrectWrongComment int x, y, z; int 3a, 1, -p; short number_one;short number+one; long TypeofCar;long #number unsigned int positive_number;… char Title; float commission, yield = 4.52; int my_data = 4; char the_initial = 'M';A char Char studentName[20] = "Anita";A string © 5/16

C KEYWORDS/RESERVED WORDS  Reserved words in C & are not available for re- definition.  have special meaning in C. auto break case char const continue default do double else enum extern float for goto if inline (C99 beyond) int long register restrict (C99 beyond) return short signed sizeof static struct switch typedef union unsigned void volatile while _Alignas (C11) _Alignof (C11) _Atomic (C11) _Bool (C99 beyond) _Complex (C99 beyond) _Generic (C11) _Imaginary (C99 beyond) _Noreturn (C11) _Static_assert (C11) _Thread_local (C11) © 6/16

OTHERS Statements are terminated with a ';' e.g: char acharacter; int i, j = 18, k = -20; printf("Initially, given j = 18 and k = -20\n"); for(; count != 0; count = count - 1) © 7/16

OTHERS  Group of statements (compound statement) are enclosed by curly braces: { and }.  Mark the start and the end of code block.  Also used in initializing a list of aggregate data values such as in array and enum type. #include int main() { int i, j = 18, k = -20; printf("Initially, given j = 18 and k = -20\n"); printf("Do some operations..." "i = j / 12, j = k / 18 and k = k / 4\n"); i = j / 12; j = k / 8; k = k / 4; printf("At the end of the operations...\n"); printf("i = %d, j = %d and k = %d\n", i, j, k); return 0; } int id[7] = {1, 2, 3, 4, 5, 6, 7}; float x[5] = {5.6, 5.7, 5.8, 5.9, 6.1}; char vowel[6] = {'a', 'e', 'i', 'o', 'u', '\0'}; enum days {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; © 8/16

COMMENTS  Single line of comment: // comment here  More than single line of comment or expanded: /* comment(s) here */ // for printf() #include #include // for strcpy_s() and their family /* main() function, where program execution starts */ int main() { /* declares variable and initializes it*/ int i = 8; … © 9/16

COMMAS  Commas separate function arguments, list of variables, aggregate values. e.g. #include int main(int argc, int argv) { int i = 77, j, k; j = i + 1; k = j + 1; i = k + j; printf("Finally, i = %d\n", i); printf("... and j = %d\n", j); printf("... and k = %d\n", k); return 0; } int id[7] = {1, 2, 3, 4, 5, 6, 7}; float x[5] = {5.6, 5.7, 5.8, 5.9, 6.1}; char vowel[6] = {'a', 'e', 'i', 'o', 'u', '\0'}; enum days {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; © 10/16

WHITESPACES  Whitespace is ignored by compiler.  Counted if used as separators or as components of character constants or string literals.  Space, tab, linefeed, carriage-return, formfeed, vertical-tab, and newline characters ( \n ). #include void main(void) { int MyAge = 12; printf("My name is Mr. C. Cplusplus\n"); … } © 11/16

SYNTAX & SEMANTIC  Programming language enforces a set of rules, symbols and special words used to construct a program.  A set of rules that precisely state the validity of the instructions used to construct C program is called syntax or 'grammar' else syntax error will be generated.  The correctness of the instructions used to write C program is called semantics or correct meaning.  These set of rules for instructions validity and correctness are monitored by the compilers.  Semantically one but can have many syntaxes. © 12/16

SYNTAX & SEMANTIC  e.g.  Pseudocode - an informal high-level description of the operating principle of a computer program or other algorithm.  Uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. To add an integer to a variable q and store the result in q (semantic), syntaxically (correct), we can write: q = q + 3; or q += 3; © 13/16

PSEUDOCODE & ALGORITHM  An informal high-level description of a computer program or algorithm operating principle.  An algorithm is merely the sequence of steps taken to solve a problem which are normally a sequence, selection, iteration and a case-type statement.  Algorithm is a procedure for solving a problem - actions to be executed and the order in which those actions are to be executed.  e.g. to sort ascendingly, the given unsorted integers, we can achieve this by using several different algorithms.  Every algorithm may have different number line of code, different repetition loops, different execution speeds etc. © 14/16

PSEUDOCODE & ALGORITHM  But all the program have similar purpose: to sort the given unsorted integers in ascending order.  Pseudocode uses programming language’s structural conventions, intended for human rather than machine reading.  helps programmers develop algorithms. © 15/16

PSEUDOCODE & ALGORITHM  e.g. Set sum to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the sum Set the class average to the sum divided by ten Print the class average. IF HoursWorked > NormalMax THEN Display overtime message ELSE Display regular time message ENDIF SET total to zero REPEAT READ Temperature IF Temperature > Freezing THEN INCREMENT total END IF UNTIL Temperature < zero Print total © 16/16