Fundamental of Programming (C)

Size: px
Start display at page:

Download "Fundamental of Programming (C)"

Transcription

1 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

2 Outline Interpreter vs. Compiler C Program Data types Variables Constants Operations Arithmetic Operators unary operators operators that require only one operand binary operators operators that require two operands Assignment Operators Equality and Relational Operators Logical Operators Bitwise Operators Conditional Operator Comma Operator sizeof Department of Computer Engineering 2/57

3 Interpreter vs. Compiler Department of Computer Engineering 3/57

4 C Program Constants and variables stdout (Screen) A B C D stderr (Screen) stdin (Keyboard) main X Y Z Instructions and operating procedures Operations and functions Department of Computer Engineering 4/57

5 Simple Program Examples: // int is return data type // main is entrance function int main() { } statement 1; statement 1; //. return 0; // Simplest c program int main() { return 0; } /* Objective: print on screen */ #include <stdio.h> // preprocessor statements have not ; int main() welcome to c!!! { printf("welcome to c!!!"); return 0; // indicate that program ended successfully } Department of Computer Engineering 5/57

6 Examples: Header file Main function Variables Input and output Process #include <stdio.h> // header file (preprocessor ) // calculating sum of two user input variables int main() { /* variable definition */ int a; int b; int result = 0; // get first variables form user printf("enter first number:\n"); scanf("%d", &a); // get scoend variables form user printf("enter scoend number:\n"); scanf("%d", &b); // sum of input variables result = a + b; printf("%d + %d = %d\n", a, b, result); system("pause"); return 0; } Department of Computer Engineering 6/57

7 #include <stdio.h> // (preprocessor ) Examples: Header file Constant Main function Variables Input and output Process #define PI 3.14 // PI constant (preprocessor ) // calculating area of circle int main() { /* variable definition */ float Radius; float Area = 0; // get radius of circle form user printf("enter Radius :\n"); scanf("%f", &Radius); // calculating area of circle Area = PI * Radius * Radius; printf( Area = %f", Area ); } system("pause"); return 0; Department of Computer Engineering 7/57

8 A Simple C Program: Printing a Line of Text Department of Computer Engineering 8/57

9 A Simple C Program: Printing a Line of Text (Cont.) Lines 1 and 2 /* Fig. 2.1: fig02_01.c A first program in C */ begin with /* and end with */ indicating that these two lines are a comment. C99 also includes the C++ language s // single-line comments in which everything from // to the end of the line is a comment. Department of Computer Engineering 9/57

10 A Simple C Program: Printing a Line of Text (Cont.) You insert comments to document programs and improve program readability. Comments do not cause the computer to perform any action when the program is run. Comments are ignored by the C compiler and do not cause any machine-language object code to be generated. Comments also help other people read and understand your program. Department of Computer Engineering 10/57

11 A Simple C Program: Printing a Line of Text (Cont.) Line 3 #include <stdio.h> Lines beginning with # are processed by the preprocessor before the program is compiled. Line 3 tells the preprocessor to include the contents of the standard input/output header (<stdio.h>) in the program. Department of Computer Engineering 11/57

12 A Simple C Program: Printing a Line of Text (Cont.) Line 6 int main( void ) Every program in C begins executing at the function main. The parentheses after main indicate that main is a program building block called a function. The keyword int to the left of main indicates that main returns an integer (whole number) value. The void in parentheses here means that main does not receive any information. A left brace, {, begins the body of every function (line 7). A corresponding right brace ends each function (line 11). This pair of braces and the portion of the program between the braces is called a block. Department of Computer Engineering 12/57

13 A Simple C Program: Printing a Line of Text (Cont.) Line 8 printf( "Welcome to C!\n" ); instructs the computer to perform an action, namely to print on the screen the string of characters marked by the quotation marks. A string is sometimes called a character string, a message or a literal. The entire line, including printf, its argument within the parentheses and the semicolon (;), is called a statement. Every statement must end with a semicolon (also known as the statement terminator). Department of Computer Engineering 13/57

14 A Simple C Program: Printing a Line of Text (Cont.) When encountering a backslash in a string, the compiler looks ahead at the next character and combines it with the backslash to form an escape sequence. The escape sequence \n means newline. Department of Computer Engineering 14/57

15 A Simple C Program: Printing a Line of Text (Cont.) Department of Computer Engineering 15/57

16 A Simple C Program: Printing a Line of Text (Cont.) Line 10 return 0; /* indicate that program ended successfully */ is included at the end of every main function. The keyword return is one of several means we ll use to exit a function. When the return statement is used at the end of main as shown here, the value 0 indicates that the program has terminated successfully. Department of Computer Engineering 16/57

17 Variables in computer A variable is a location in memory where a value can be stored for use by a program. Department of Computer Engineering 17/57

18 Variables 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 may be given representations containing multiple characters A-Z, a-z, 0-9, and _ (underscore character) First character must be a letter or underscore (no, _no 9no) Usually only the first 32 characters are significant There can be no embedded blanks (student no) Identifiers are case sensitive (area, Area, AREA, ArEa) Keywords cannot be used as identifiers Department of Computer Engineering 18/57

19 Reserved Words (Keywords) in C auto break int long case char register return const continue short signed default do sizeof static double else struct switch enum extern typedef union float for unsigned void goto if volatile while Department of Computer Engineering 19/57

20 Naming Conventions C programmers generally agree on the following conventions for identifier: Use meaningful identifiers Separate words within identifiers with: underscores capitalize each word Examples: surface_area (prefferd 1 ) Surface_Area surfacearea SurfaceArea 1- Details: Department of Computer Engineering 20/57

21 Variable declaration Before using a variable, you must declare it Data_Type Identifier; int width; // width of rectangle float area; // result of calculating area stored in it char separator; // word separator Data_Type Identifier = Initial_Value; int width = 10; // width of rectangle float area = 255; // result of calculating area stored in it char seperator =, ; // word separator Data_Type Identifier, Identifier, Identifier,.; int width, length, temporary; float radius, area = 0; Department of Computer Engineering 21/57

22 Variable declaration When we declare a variable Space is set aside in memory to hold a value of the specified data type That space is associated with the variable name That space is associated with a unique address Visualization of the declaration int width = 95; // get width form user // &width is 22ff40 // *&width is 95 // sizeof width is 4 & * address data 22ff ff44 Department of Computer Engineering 22/57

23 Data types Minimal set of basic data types primitive data types int float double char Void The size and range of these data types may vary among processor types and compilers In code blocks: int 4 byte float 4 byte char 1 byte double 8 byte Department of Computer Engineering 23/57

24 Write a program that show size of data type in code blocks. Department of Computer Engineering 24/57

25 Data type qualifiers Modify the behavior of data type to which they are applied: Size qualifiers: alter the size of the basic data types: short: multiply by 0.5 long: multiply by 2 short can be applied to: int long can be applied to: int and double Sign qualifiers: can hold both positive and negative numbers, or only positive numbers.: signed: + and - unsigned: + they can be applied to : int and char Department of Computer Engineering 25/57

26 Data type size and range Data type Qualifier Example Size (byte) Range char signed unsigned signed char c; unsigned char c; char c; int signed unsigned short long signed short i; signed short int i; unsigned int i; int i; signed int i; short i; short int i; long i; long int i; signed long i; signed long int i; long long i; long long int i; signed long long i; signed long long int i; or or or signed (16): unsigned (16): signed (32): unsigned (32): float float f; 64 +/- 3.4e +/- 38 (~7 digits) double long double d; long double d; /- 1.7e +/- 308 (~15 digits) Department of Computer Engineering 26/57

27 Overflow and Underflow /* The # character indicate a pre-processor directive; it's an instruction to the compiler to make it do something The <> character tell C to look in the system area for the file stdio.h. If I had given the name #include "stdio.h" instead it would tell the compiler to look in the current directory /* #include <stdio.h> /* * Function main begins program execution * Semi-colon is statement terminator, so it is as a signal to the compiler for end of line */ int main() { /* The 2 curly brackets { }, are used to specify the limits of the program block */ char letter = 'A'; // char variable to show ASCII code short shortvariable = 32769; // short variable for test overflow } // printf command display string on the monitor printf("current value of shortvariable is = %d\n", shortvariable); printf("current value of letter is = %d", letter); printf("current value of letter is = %c", letter); system("pause"); // pause the execution to show press any key return 0; // indicate that program ended successfully current value of shortvariable is = current value of letter is = 65 current value of letter is = A Department of Computer Engineering 27/57

28 Program Error Compile-time or syntax is caused when the compiler cannot recognize a statement Run-time E.g. division by zero Logical E.g. Overflow and Underflow Department of Computer Engineering 28/57

29 Examples: Header file Constant Main function Variables Input and output Process #include <stdio.h> // (preprocessor ) #define PI 3.14 // PI constant (preprocessor ) // calculating area of circle int main() { /* variable definition */ float Radius; float Area = 0; // get radius of circle form user printf("enter Radius :\n"); scanf("%f", &float ); // calculating area of circle Area = PI * Radius * Radius; printf( Area = %f", Area ); } system("pause"); return 0; Department of Computer Engineering 29/57

30 Integer constant value Base 10: Base 8: Base 16: 0x1 0X5 0x7fab unsigned: 5000u 4U long: l 56L unsigned long: ul long long : LL 25lL Example : 0xABu 0123uL 017LL Department of Computer Engineering 30/57

31 floating-point constant value A floating-point value contains a decimal point For example, the value is represented in scientific notation as X 10 2 and is represented in exponential notation (by the computer) as E+02 This notation indicates that is multiplied by 10 raised to the second power (E+02) The E stands for exponent Department of Computer Engineering 31/57

32 Char and string constant value Char char c; c = 'A'; // d = 65; String printf("string is array of char!!!"); printf("example of escape sequence is \n"); Department of Computer Engineering 32/57

33 Constant Constants provide a way to define a variable which cannot be modified by any other part in the code #define: const: #define Identifier without memory consume memory consume constant_value #define PI 3.14 #define ERROR "Disk error " #define ERROR "multiline \ message" #define ONE 1 #define TWO ONE + ONE Department of Computer Engineering 33/57

34 Constant const [Data_Type] Identifier = constant_value; const p = 3; // const int p = 3; const p; p = 3.14; const p = 3.14; const float p = 3.14; // compile error // p = 3 because default is int Department of Computer Engineering 34/57

35 #include <stdio.h> // (preprocessor ) Examples: Header file Constant Main function Variables Input and output Process #define PI 3.14 // PI constant (preprocessor ) // calculating area of circle int main() { /* variable definition */ float Radius; float Area = 0; // get radius of circle form user printf("enter Radius :\n"); scanf("%f", &float ); // calculating area of circle Area = PI * Radius * Radius; printf( Area = %f", Area ); } system("pause"); return 0; Department of Computer Engineering 35/57

36 Operators Arithmetic Operators unary operators operators that require only one operand binary operators operators that require two operands Assignment Operators Equality and Relational Operators Logical Operators Bitwise Operators Conditional Operator Comma Operator sizeof Operator Width * High Operand Department of Computer Engineering 36/57

37 Arithmetic Operators Unary Operator C operation Operator Expression Explanation Positive + a += 3; Equivalent to a = a + 3 Negative - b -= 4; Equivalent to b = b - 4 Increment ++ i++; Equivalent to i = i + 1 Decrement - - i - -; Equivalent to i = i - 1 Department of Computer Engineering 37/57

38 PRE / POST Increment Consider this example: int width = 9; printf("%d\n", width++); printf("%d\n", width); But if we have: int width = 9; printf("%d\n", ++width); printf("%d\n", width); int width = 9; printf("%d\n", width); width++; printf("%d\n", width); int width = 9; width++; printf("%d\n", width); printf("%d\n", width); Department of Computer Engineering 38/57

39 PRE / POST Increment int R = 10; int count = 10; ++ Or -- Statement Equivalent Statements R count R = count; R = count++; count = count + 1; count = count + 1; R = ++count; R = count; R = count; R = count--; count = count 1; 10 9 count = count 1; R = --count; R = count; 9 9 Department of Computer Engineering 39/57

40 Arithmetic Operators Binary Operators C operation Operator Expression Addition + b = a + 3; Subtraction - b = a 4; Multiplication * b = a * 3; Division / b = a / c; Modulus (integer) % b = a % c; Department of Computer Engineering 40/57

41 Division The division of variables of type integer will always produce a variable of type integer as the result Since b is declared as an integer, the result of a/2 is 3, not 3.5 Example int a = 7, b; float z; b = 3, z = b = a / 2; z = a / 2.0; printf("b = %d, z = %f\n", b, z); Department of Computer Engineering 41/57

42 Modulus You could only use modulus (%) operation on integer variables (int, long, char) z = a % 2.0; // error z = a % 0; // error Example int a = 7, b, c; b = a % 2; c = a / 2; printf("b = %d\n", b); printf("c = %d\n", c); Modulus will result in the remainder of a/ a/ a%2 remainder integral Department of Computer Engineering 42/57

43 Assignment Operators lvalue = rvalue; int i; float f; i = 2; // *&i = 2; 2 = i; // error: invalid lvalue in assignment f = 5.6; i = f; // i = 5; i = -5.9; // i = -5; Department of Computer Engineering 43/57

44 Assignment Operators Assignment operators are used to combine the '=' operator with one of the binary arithmetic or bitwise operators. Operator Expression Equivalent Statement Results += c += 7; c = c + 7; c = 16 -= c -= 8; c = c 8; c = 1 *= c *= 10; c = c * 10; c = 90 /= c /= 5; c = c / 5; c = 1 %= c %= 5; c = c % 5; c = 4 &= c &= 2 ; c = c & 2; c = 0 ^= c ^= 2; c = c ^ 2; c = 11 = c = 2; c = c 2; c = 11 <<= c <<= 2; c = c << 2; c = 36 >>= c >>= 2; c = c >> 2; c = 2 Department of Computer Engineering 44/57

45 Precedence Rules The rules specify which of the operators will be evaluated first For example: x = 3 * a - ++b%3; c = b = d = 5; Precedence Operator Associativity Level 1 (highest) () left to right 2 unary right to left 3 * / % left to right left to right 5 (lowest) = += -= *= /= %= right to left Department of Computer Engineering 45/57

46 Precedence Rules how would this statement be evaluated? x = 3 * a - ++b % 3; What is the value for x, for: a = 2, b = 4? x = 3 * a - ++b % 3; x = 3 * a - 5 % 3; x = 3 * a - 5 % 3; x = 6-5 % 3; x = 6 2; x = 4; Department of Computer Engineering 46/57

47 Precedence Rules If we intend to have a statement evaluated differently from the way specified by the precedence rules, we need to specify it using parentheses ( ) x = 3 * a - ++b % 3; Consider having the following statement: x = 3 * ((a - ++b)%3); the expression inside a parentheses will be evaluated first The inner parentheses will be evaluated earlier compared to the outer parentheses Department of Computer Engineering 47/57

48 Precedence Rules how would this statement be evaluated? x = 3 * ((a - ++b)%3); What is the value for X, for: a = 2, b = 4? x = 3 * ((a - ++b) % 3); x = 3 * ((a - 5) % 3); x = 3 * ((-3) % 3); x = 3 * 0; x = 0; Department of Computer Engineering 48/57

49 Precedence Rules how would this statement be evaluated? x = 3 * ++a b--%3; What is the value for X, for: a = 2, b = 4? x = 3 * ++a b-- % 3; x = 3 * ++a b-- % 3; x = 3 * ++a 4 % 3; x = 3 * 3 4 % 3; x = 9 1; x = 8; b = b -1, b = 3; Department of Computer Engineering 49/57

50 Equality and Relational Operators Equality Operators: Relational Operators: Operator Example Meaning == x == y x is equal to y!= x!= y x is not equal to y Operator Example Meaning > x > y x is greater than y < x < y x is less than y >= x >= y x is greater than or equal to y <= x <= y x is less than or equal to y Department of Computer Engineering 50/57

51 Logical Operators Logical operators are useful when we want to test multiple conditions AND OR NOT C has not bool data type, but: 0: evaluate to false If(0) printf(" "); other: evaluate to true If(1) printf(" "); If(-13) printf(" "); Department of Computer Engineering 51/57

52 && - Logical AND All the conditions must be true for the whole expression to be true Example: if (a == 1 && b == 2 && c == 3) means that the if statement is only true when a == 1 and b == 2 and c == 3 If (a = 5) e1 e2 Result = e1 && e Department of Computer Engineering 52/57 e1 e2 Result = e1 && e2 false false false false true false true false false true true true

53 - Logical OR The truth of one condition is enough to make the whole expression true Example: if (a == 1 b == 2 c == 3) means the if statement is true when either one of a, b or c has the right value e1 e2 Result = e1 e Department of Computer Engineering 53/57 e1 e2 Result = e1 e2 false false false false true true true false true true true true

54 ! - Logical NOT Reverse the meaning of a condition Example: if (!(radius > 90)) Means if radius not bigger than 90. e1 Result =!e e1 Result =!e1 false true false true true false true false Department of Computer Engineering 54/57

55 Bitwise Operators Apply to all kinds of int and char types: signed and unsigned char, short, int, long, long long Operator Name Description & AND Result is 1 if both operand bits are 1 OR Result is 1 if either operand bit is 1 ^ XOR Result is 1 if operand bits are different ~ Not (Ones Complement) Each bit is reversed << Left Shift Multiply by 2 >> Right Shift Divide by 2 Department of Computer Engineering 55/57

56 Bitwise Operators Applicable for low level programming, e.g.: Port manipulation I/O programming Usually: & ^ set OFF one bit set ON one bit reverse one bit Department of Computer Engineering 56/57

57 XOR e1 e2 Result = e1 ^ e Department of Computer Engineering 57/57

58 Examples A = 199; B = 90; c = a & b = 66; c = a b = 233; c = a ^ b = 157; c = ~a = 56 c = a << 2 = 28; c = a >> 3 = 24; Department of Computer Engineering 58/

59 Conditional Operator The conditional operator (?:) is used to simplify an if/else statement Condition? Expression1 : Expression2; The statement above is equivalent to: if (Condition) Expression1; else Expression2; Which are more readable? Department of Computer Engineering 59/57

60 Conditional Operator Example: if/else statement: if (total > 12) grade = P ; else grade = F ; conditional statement: (total > 12)? grade = P : grade = F ; OR grade =( total > 12)? P : F ; Department of Computer Engineering 60/57

61 Conditional Operator Example: if/else statement: if (total > 12) printf( Passed!!\n ); else printf( Failed!!\n ); Conditional Statement: printf( %s!!\n, total > 12? Passed : Failed ); Department of Computer Engineering 61/57

62 Comma Operator (Expression1,Expression2, ); Example: int x, y, z; z = (x = 2, y = x + 1); printf("z = %d", z); int x, y, z; x = 2; y = x + 1; z = y; printf("z = %d", z); Department of Computer Engineering 62/57

63 sizeof The sizeof keyword returns the number of bytes of the given expression or type returns an unsigned integer result sizeof variable_identifier; sizeof (variable_identifier); sizeof (Data_Taype); Example: int x; printf("size of x = %d", sizeof x); printf("size of long long = %d", sizeof(long long)); printf("size of x = %d", sizeof (x)); Department of Computer Engineering 63/57

64 Type Casting Explicit Type cast: carried out by programmer using casting int k, i = 7; float f = 10.14; char c = 'B'; k = (i + f) % 3; // error k = (int)(i + f) % 3; Implicit Type cast: carried out by compiler automatically f = 65.6; i = f; // f = (int)f; c = i; // c = (int)i; Department of Computer Engineering 64/57

65 Type Casting char c = 'A'; short s = 1; int i; float f; double d; d = (c / i) + (f * d) + (f + i); (char) (int) (float) (double) (float) (int) int double float double i = (c + s); (int) (char) (short) double (short) (int) Department of Computer Engineering 65/57

66 Precedence Rules Primary Expression Operators () []. -> left-to-right Unary Operators * & + -! ~ ++expr --expr (typecast) sizeof right-to-left * / % + - >> << < > <= >= Binary Operators ==!= & left-to-right ^ && Ternary Operator?: right-to-left Assignment Operators = += -= *= /= %= >>= <<= &= ^= = right-to-left Post increment expr++ expr-- - Comma, left-to-right Department of Computer Engineering 66/57

67 Good Programming Practices Place each variable declaration on its own line with a descriptive comment Place a comment before each logical chunk of code describing what it does Do not place a comment on the same line as code with the exception of variable declarations Use spaces around all arithmetic and assignment operators Use blank lines to enhance readability Department of Computer Engineering 67/57

68 Good Programming Practices AVOID: variable names starting with an underscore often used by the operating system and easy to miss Place a blank line between the last variable declaration and the first executable statement of the program Indent the body of the program Use all uppercase for symbolic constants (used in #define preprocessor directives) Examples: #define PI #define AGE 52 Department of Computer Engineering 68/57

Fundamentals of Programming

Fundamentals 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 information

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

Have 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 information

C: How to Program. Week /Mar/05

C: 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 information

Chapter 2 - Introduction to C Programming

Chapter 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 information

Introduction 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 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 information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

More information

Fundamental 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 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 information

Chapter 1 & 2 Introduction to C Language

Chapter 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 information

Programming and Data Structures

Programming 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 information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT 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 information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

Character 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. 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 information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants 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 in C 2.6 Decision

More information

Work relative to other classes

Work 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 information

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

2.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 information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Chapter 4: Basic C Operators

Chapter 4: Basic C Operators Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

More information

UNIT- 3 Introduction to C++

UNIT- 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 information

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

Full 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 information

A Fast Review of C Essentials Part I

A 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 information

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

UNIT 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 information

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14 Variables in C CMSC 104, Spring 2014 Christopher S. Marron (thanks to John Park for slides) 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What

More information

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

c) 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 information

CSc 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 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 information

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

LESSON 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 information

ANSI C Programming Simple Programs

ANSI 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 information

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

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 information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More information

Programming 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 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 information

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park Variables in C CMSC 104, Fall 2012 John Y. Park 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What Are Variables in C? Variables in C have the

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

6.096 Introduction to C++ January (IAP) 2009

6.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 information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC 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 information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

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

Variables 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 information

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock) C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the

More information

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 1 By the end of this lecture, you will be able to identify

More information

Data Types and Variables in C language

Data 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 information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

More information

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java 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 information

Programming. Elementary Concepts

Programming. Elementary Concepts Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions

More information

CS102: Variables and Expressions

CS102: Variables and Expressions CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions 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 information

Course Outline Introduction to C-Programming

Course 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 information

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

A 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 information

Reserved Words and Identifiers

Reserved 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 information

Objectives. 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++ 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 information

Chapter 2: Basic Elements of C++

Chapter 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 information

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic 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 information

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

Chapter 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 information

Operators. Java operators are classified into three categories:

Operators. 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 information

Fundamental of C programming. - Ompal Singh

Fundamental of C programming. - Ompal Singh 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

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

More information

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

UNIT-2 Introduction to C++

UNIT-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 information

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

C 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 information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 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 information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

Programming 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] 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 information

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review.  1 CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions 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 information

ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

More information

Creating a C++ Program

Creating 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 information

C 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 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 information

Basics of Programming

Basics 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 information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

More information

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

C 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 & 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 information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1 300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard

More information

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!

More information

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

C 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 information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

ET156 Introduction to C Programming

ET156 Introduction to C Programming ET156 Introduction to C Programming g Unit 22 C Language Elements, Input/output functions, ARITHMETIC EXPRESSIONS AND LIBRARY FUNCTIONS Instructor : Stan Kong Email : skong@itt tech.edutech.edu General

More information

C - Basic Introduction

C - 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 information

Basics of Java Programming

Basics 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 information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 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 information

Introduction to Programming

Introduction to Programming Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

More information

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

UNIT - 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 information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 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 information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

A flow chart is a graphical or symbolic representation of a process.

A flow chart is a graphical or symbolic representation of a process. Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information