std::cout << "Size of long = " << sizeof(long) << " bytes\n\n"; std::cout << "Size of char = " << sizeof(char) << " bytes\n";

Size: px
Start display at page:

Download "std::cout << "Size of long = " << sizeof(long) << " bytes\n\n"; std::cout << "Size of char = " << sizeof(char) << " bytes\n";"

Transcription

1 C++ Program Structure A C++ program must adhere to certain structural constraints. A C++ program consists of a sequence of statements. Every program has exactly one function called main. Programs are built using one or more files, along with the usage of predefined libraries. Statements are the smallest complete executable unit of a program. There are three types: 1. Declaration statements 2. Expression statements 3. Compound statements -- sets of statements enclosed in set braces (often called a block) C and C++ programs usually consist of multiple files and at least one library A library is precompiled code available to the programmer to perform common tasks; the location of the library code is known to the compiler The library is defined for the program via an interface, or header file By using the #include<> directive a library is made a part of your program Other files may also be made part of the program using #include<> directives. Non-library files locations are not known to the compiler and thus must be given to the compiler explicitly. The other form of #include" " directive, using quotes instead of angle brackets, is used only when the included file is in the same directory as the one where the compile command is invoked. This form is not recommended. The reason use of the form #include" " is not recommended: use of "" builds an assumption about the location of files into the source code file itself. Using <> makes the project structure independent of location of files, leaving the location issues to the project build, where they are handled with the -I compile option. It is very common for project files to be developed in one directory and then migrate into various directories after development. Using <> makes the code files independent of changes in file location, whereas using "" means the files would have to be edited when their locations change. Native Data Types Native (aka "built in" or "atomic") data types are the types defined by the C++ language. Signed integer types: char, short, int, long Unsigned integer types: unsigned char, unsigned short, unsigned int, unsigned long Floating point types: float, double, long double Special type: bool (has values true and false) The sizes for the various types are implementation dependent, with some constraints. The size of char is typically one byte, and the sizes must be non-decreasing as you read from left to right in these lists. To see what a particular installation uses, run this program: #include <iostream> int main() std::cout << "Size of bool = " << sizeof(bool) << " bytes\n\n"; std::cout << "Size of char = " << sizeof(char) << " bytes\n"; std::cout << "Size of short = " << sizeof(short) << " bytes\n"; std::cout << "Size of int = " << sizeof(int) << " bytes\n"; std::cout << "Size of long = " << sizeof(long) << " bytes\n\n"; std::cout << "Size of unsigned char = " << sizeof(unsigned char) << " bytes\n"; std::cout << "Size of unsigned short = " << sizeof(unsigned short) << " bytes\n"; std::cout << "Size of unsigned int = " << sizeof(unsigned int) << " bytes\n"; std::cout << "Size of unsigned long = " << sizeof(unsigned long) << " bytes\n\n"; std::cout << "Size of float std::cout << "Size of double std::cout << "Size of long double = " << sizeof(float) << " bytes\n"; = " << sizeof(double) << " bytes\n"; = " << sizeof(long double) << " bytes\n"; 1/13

2 return 0; The sizeof() function may be applied to user-defined types as native types. It also applies to variables. The return value is in units of bytes. Declared Variable Attributes Every declared variable has the following attributes: A name, chosen by the programmer, aka identifier A type, specified in the declaration of the variable A size, determined by the type A value, the data stored in the variable's memory location An address, the location in memory where the value is stored The storage class, determining how the variable is situated in memory The scope, determining when the variable is "visible" in the source code The linkage, used in multifile programs The declaration of variables is discussed later in this chapter. Declared variables are static, meaning that (1) they have names that are fixed and determined at the time and place they are declared and (2) there is memory bound to the variable at the time the program is compiled. We say that these variables are bound to memory at compile time. When a program is compiled, a symbol table is created mapping the static variable name to its type, size, address and other attributes. Another kind of variable is bound at run time and called dynamic. These are discussed in another chapter. Naming Variables The names of variables (and other identifiers chosen by the programmer, such as names of constants, classes, and types) are subject to constraints: Identifiers may consist of letters, digits, and underscores An identifier must start with a non-digit; leading with underscore is best reserved for special purposes related to language implementation and support C++ is case sensitive Reserved words may not be used as identifiers Here is a list of reserved keywords in C++: asm auto bad_cast bad_typeid bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum except explicit extern false finally float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try type_info typedef typeid typename union unsigned using virtual void volatile while Note that other words are defined in standard libraries and are therefore reserved implictly. Examples 2/13

3 include: size_t (defined in <stdlib>) and wchar_t (defined in <iostream>). Declaring Variables The basic format for declaration is: typename variablename; Note that the left-hand item is a type, and must be understood as such by the compiler. The right-hand item is the identifier chosen by the programmer. The following are some examples of declarations: int x; float y; int a, b, c; // can also list several variables in one declaration // statement, separated by commas int a=0, b=0, c; // can also initialize variables in // declaration statements int a(0), b(0), c; // alternate syntax for initialization A variable can be declared constant by using the keyword const; a constant must be initialized in the same statement, as in the following example: const double PI = ; Here are more examples: int main() int x; float average; char letter; int y = 0; int bugs, daffy = 3, sam; double larry = 2.4, moe = 6, curly; char c, ch = 't', option; long a; long double ld; unsigned int u = 12; Literals integer literal -- an actual integer number written in code (4, -10, 18) float literal -- an actual decimal number written in code (4.5, -12.9, 5.0) -- Note: these are interpreted as type double by most C++ compilers character literal -- a character in single quotes: ('F', 'a', '\n') string literal -- a string in double quotes: ("Hello", "Bye", "Wow!\n") Comments A comment in a program is a portion that is ignored by the compiler. The very important purpose of comments is to serve the humans who create, read, and maintain the code. The C block-style technique of 3/13

4 commenting carries over to C++, i.e., comments can be enclosed in delimiters /* (comment here) */. This form of comment is useful for multiple lines of commentary. /* This is a comment. It can stretch over several lines. */ C++ allows an additional comment style, designed for shorter remarks embedded in code but suitable for only one line of comment: int x; x = 3; // This is a comment that ends at the end of this line // This is a comment that ends at the end of this line Everything from the double slash // to the end of the line is a comment. Operators Operators are functions with special evaluation syntax. It's a good idea to keep in mind that operators are functions, because the function evaluation syntax must be used when re-defining operators, a topic we will study in this course. Here is an example of the familiar addition operator used with operator syntax and operator function syntax: int x, y, z; // declare three int variables... // code that gives x and y each a value z = x + y; // operator syntax z = operator+(x,y); // operator function syntax The last two lines of this code have identical behavior: z is assigned a value equal to the sum of x and y. A unary operator is an operator function that has one operand. A binary operator is an operator function that has two operands. A ternary operator is an operator function that has three operands. With the exception of the "conditional expression" operator expr? expr : expr inherited from C, all C++ operators are either unary or binary. C++ has a very rich set of operators. (There are 67 C++ operators listed on pp of [Stroustrup], with 18 levels of precedence.) We will discuss only a few here. Others will be introduced as they are needed. Arithmetic Operators The basic arithmetic operators are defined as native for integer types as follows: Name Symbol Type Usage Add + binary x + y Subtract - binary x - y Multiply * binary x * y Divide / binary x / y Modulo % binary x % y Minus - unary -x These operators perform arithmetic as expected for integers. Note that division x/y produces the quotient and modulo x%y produces the remainder when x is divided by y. All but modulo are overloaded for floating point types and have meaning as expected in that context. Here is an illustration: 4/13

5 int p = 23, q = 5, r; float x = 23, y = 5, z; r = p / q; // r has the value 4 r = p % q; // r has the value 3 z = x / y; // z has the value 4.6 When doing an arithmetic operation on two operands of the same type, the result is also the same type. What about operations on mixed types? Suppose we have the declarations int x = 5; float y = 3.6; If we do (x + y), what type will the result have? In this case, a float. The rule is: an arithmetic operation on two mixed types returns the larger type. The result of (x + y) will be 8.6. Please keep in mind that we are glossing over the issue of internal representation. A computer uses binary representation for internal storage of numbers. We are using decimal representation in this discussion. Decimal notation is only an external representation for human use. This is what we would see if we output the values to screen. Operator Precedence As noted above, there are 18 levels of operator precedence in C++, way beyond the scope of this review. (We will encounter many of these operators during this course, but not all.) This is both very rich and extraordinarily complicated to remember. The best rule is: When in doubt, use parentheses to force the order of operator evaluation. For the more familiar and oft-used operators, however, it is easy to remember their syntax, precedence, and associativity. Here is a table of most of the C++ operators: Common C++ Operators, Grouped by Precedence (High to Low) Name binary scope resolution binary scope resolution unary (global) scope resolution Usage class_name :: member namespace_name :: member :: name value construction run-time checked conversion compile-time checked conversion unchecked conversion const conversion post increment post decrement member selection member selection type expr dynamic_cast<type> ( expr ) static_cast<type> ( expr ) reinterpret_cast<type> ( expr ) const_cast<type> ( expr ) Lvalue++ Lvalue-- object.member pointer->member bracket operator pointer [ expression ] function call function ( parameter list ) 5/13

6 size of object sizeof expression size of type sizeof ( type ) pre increment ++Lvalue pre decrement --Lvalue not! expression unary minus - expression address of & lvalue dereference * pointer create new type destroy delete type member selection member selection object.*pointer-tomember pointer->*pointer-tomember multiply divide modulo expr * expr expr / expr expr % expr add subtract expr + expr expr - expr shift left shift right expr << expr expr >> expr less than less than or equal greater than greater than or equal expr < expr expr <= expr expr > expr expr >= expr equal not equal expr == expr expr!= expr bitwise AND expr & expr bitwise XOR expr ^ expr bitwise OR expr expr logical AND expr && expr logical OR expr expr conditional expression expr? expr : expr 6/13

7 assignment multiply and assign divide and assign modulo and assign add and assign subtract and assign shift left and assign shift right and assign bitwise AND and assign bitwise OR and assign bitwise XOR and assign lvalue = expr lvalue *= expr lvalue /= expr lvalue %= expr lvalue += expr lvalue -= expr lvalue <<= expr lvalue >>= expr lvalue &= expr lvalue = expr lvalue ^= expr throw exception throw expr comma (sequencing) expr, expr Note that the arithmetic operators have relative precedence in the language that follows normal mathematical usage. Note also that assignment (and its embelishments) have very low precedence, so that in a statement such as x = a + b * c; the evaluation is as you would hope and expect, namely x is assigned the value a + ( b * c ). There are suprises lurking in all this complexity, however, so remember the "when in doubt" rule. Increment and Decrement C++ has a number of unary operators. Among the most used are the four increment/decrement operators: int x,y;... ++x; // prefix increment same as x = x + 1; returns reference to (new) x x++; // postfix increment same as x = x + 1; returns value of old x --x; // prefix decrement same as x = x - 1; returns reference to (new) x x--; // postfix decrement same as x = x - 1; returns value of old x Note the distinction between the pre- and post- versions. The prefix returns a reference to the (newly updated) variable. The postfix returns the value of the variable before updating it. The behaviors are illustrated in this code example: x = 2; y = ++x; // x and y have the value 3 y = x++; // y has the value 3 and x has the value 4 Because the postfix versions of increment/decrement must build and return a value, they are slightly less efficient than the prefix versions. It is therefore good practice to use the prefix versions unless there is a specific need for postfix. Operator Associativity Each operator has a default associativity used when an otherwise ambiguous expression is formed. For 7/13

8 example, the statement sum = x + y + z; is technically ambiguous, because operator+(, ) requires exactly two arguments, and there are three in the statement. The default associativity takes over in such situations to provide consistent meaning: sum = x + y + z; sum = (x + y) + z; // statement meaning identical to first That is, first x and y are added, then z is added to the result. For this operator, default associativity is leftto-right, or LR. Most binary operators have LR default associativity. A notable exception is the assignment operator = which associates right-to-left (RL): a = b = c; // valid statement a = (b = c); // identical meaning That is, first c is assigned to b, then b is assigned to a. The result is that all three variables a, b, and c have the same value. Assignment and Equality Operators The symbol = has ambiguous meaning in algebra, sometimes asserting that two things have the same value (as in "let x = y"), and other times asking the question whether two things have the same value (as in "solve x = y"). These two usages must be separated in a programming language. The first is assignment and is done in C/C++ with operator =. The second is equality and is done in C/C++ with operator ==. These two operators are very different in meaning and useage. Unfortunately, they are very similar in appearance, which can cause problems debugging programs when they are inadvertantly interchanged. Assignment is an operator that first, as a side effect, makes its Lvalue (the operand on its left) equal to its Rvalue (the operand on its right), and second returns a reference to the (new) Lvalue). Here are some example usages: x = 5; // x is assigned the value 5 y = 10; // y is assigned the value 10 z = x + y; // z is assigned the value of the expression x + y, // which is evaluated first, obtaining 15, which is assigned to z Equality is an operator that returns "true" or "false" (either a boolean value or an integer), depending on whether the arguments are in fact equal or not. Equality is commonly used to test for conditional branching or loop termination: if ( x == y ) z = 1; else z = 2; do whatever(); while (x == 100); // conditionally execute one of two statements // conditionally terminate loop There is an entire family of assignment operator derivatives, such as operator += and operator &=. There is another family of equality/inequality operators such as operator < and operator >=. Implicit Type Conversion 8/13

9 Whenever a variable of an unexpected type is used in an expression, either the ambiguities must be resolved by implicit, or "automatic" type conversion, or an error will occur. The general rule is that when there is a known rule for converting the unexpected type to the expected type, that rule will be invoked and computation can proceed. For example, when the types on the left and right sides of an assignment statement do not match, that is, the Rvalue and Lvalue have different types, the assignment statement is allowed to proceed if and only if there is a way provided to convert from the Rvalue type to the Lvalue type. For native types, there is generally a way to convert from smaller types to larger types but not the reverse. (Care must also be taken when converting between signed and unsigned types of the same size.) Similarly, when mixed types appear in an arithmetic expression, the types will be converted to the largest type appearing in the expression: char a, b; int m, n; float x, y; unsigned int u, v; m = a; // OK a = m; // error x = m; // OK u = m; // dangerous - possibly no warning x = a + n; // result of (a + n) is type int; converted to type float for assignment Type conversion is another place where a "when in doubt" rule should be used: When in doubt, make type conversions explicit. Explicit Type Conversion: Casting It is excellent practice to always explicitly convert types rather than rely on the compiler, which may not always know the programmer's intent. Most experienced programmers use implicit type conversion only within one of these two families of native types: Signed Family = char, short, int, long, float, double, long double Unsigned Family = unsigned char, unsigned short, unsigned int, unsigned long and otherwise use explicit type conversion in the form of cast operators. The C cast operator is invoked like this: c = (char)y; x = (int)b; // cast a copy of the value of y as a char, and assign to c // cast a copy of the value of b as an int, and assign to x C++ installations may or may not recognize the C cast operator. C++ has a richer set of casting operators that give the programmer better control of how and when the type conversion occurs. The analog of C casting is the operator static_cast<type_name>(expr), which converts the value of expr to type type_name. This new style cast is invoked like this: c = static_cast<char>(y); x = static_cast<int>(b); There are two other C++ cast operators, dynamic_cast<type_name>(expr) and reinterpret_cast<type_name>(expr). The angle brackets in these operators are used to denote template parameter arguments, a topic we will cover later in the course. Scope The scope of a variable is the portion of the source code where the variable is valid, or "visible", to the computational context. Scope is determined implicitly by program structure. A variable that is declared outside of any compound blocks and is usable anywhere in the file from its point 9/13

10 of declaration is called a global variable and is said to have global scope. A variable declared within a block (i.e. a compound statement) has scope only within that block. C++ allows the declaration of variables anywhere within a program, subject to the declare before use rule. C requires variable declarations at the beginning of a block. Here is code illustrating scope of three variables: // scopes: // x i j k float x; // int main() // // int i; // for (int j = 0; j < 100; ++j) // // std::cin >> i; // int k = i; // // more code // // return 0; // // Note that x is global, i and j are local. The following code is more subtle. #include <iostream> int main() std::cout << "\nstarting Program\n"; int x = 5; // declare new variable std::cout << "x = " << x << '\n'; int x = 8; std::cout << "x = " << x << '\n'; std::cout << "x = " << x << '\n'; x = 3; std::cout << "x = " << x << '\n'; You can run the program to be sure you understand how scope rules affect the values of the variables. Namespaces Namespaces are also used to limit the scope of identifiers. A namespace is created using the namespace key word as follows: // filename: mystuff.h namespace mystuff // declare, define things here, such as int myfunction (int x) // code here // end namespace mystuff Any declarations and definitions made within the namespace block will not be in the global namespace, but will be in the namespace mystuff. Thus statements using items from mystuff must "resolve" the scope 10/13

11 with a scope resolution operator ::, as in this code: #include < mystuff.h > int x, y; x = myfunction(y); // error - unrecognized identifier x = mystuff::myfunction(y); // OK - namespace resolved Implicit namespace resolution may be used by invoking a using directive, as follows: #include < mystuff.h > using mystuff; // includes mystuff into global namespace int x, y; x = myfunction(y); // OK x = mystuff::myfunction(y); // OK A namespace may be opened and added to in several places, which enhances the convenience of their use. For example, several different files could add items to the mystuff namespace. Namespaces are extremely useful when more than one person is working on code for a single project, a situation quite common in the professional world. Using namespaces can prevent name conflicts and ambiguities created when two programmers (or one programmer at two different times) happen to use the same identifier for different purposes. In general, global variables should be avoided. For this reason, the using directive should also be avoided in this course. Storage Class and Linkage The storage class of a variable determines the period during which it exists in memory. (Note that this period must be at least as long as the variable is in scope, but it may excede that time.) There are two storage classes: automatic and static. Confusingly, C++ provides five storage class specifiers which determine not just the storage class but also other things such as linkage and how the variable is treated by various components of a running program. The storage class specifiers are as follows: Storage class automatic: The variable is ensured to be in memory only when it is in scope. 1. Storage class specifier: auto This is the default specifier for all local variables, hence it is rarely seen used explicitly. It states the variable has storage class automatic. 2. Storage class specifier: register This specifies storage class automactic and also advises the compiler to place the variable into a CPU register instead of normal memory. This is an optimization suggestion but has no effect on the access logic for the variable. Storage class static: The variable is ensured to be in memory during the entire execution of the program, regardless of whether the variable is in or out of scope. 3. Storage class specifier: extern This is the default for all global variables, including ordinary variables and function names. Extern variables are visible even across multiple files of source code, however, when an extern variable is defined in one file and used by another file, it must be declared in the second file using the extern specifier. 4. Storage class specifier: static The same as extern except that scope is limited to the file in which the variable is defined. A local variable may be specified as static, thus changing its storage class from the default automatic to static, with scope limited to the containing file. 5. Storage class specifier: mutable This specifier is used exclusively for classes and will be discussed later in that context. Clearly these specifiers affect the storage class, the linkage, and in some cases the scope of the variable. 11/13

12 C++ Standard I/O In C, I/O (Input/Output) is handled with functions found in stdio.h: printf and scanf. These are examples of "formatted" I/O statements and assume a certain file-oriented format. In C++, I/O is handled through objects called streams. This is a very useful, flexible, and programmermodifiable system; it is also somewhat complex. We will begin using two streams cin and cout that are pre-defined in the library iostream. cin is an object of type istream and cout is an object of type ostream. These stream objects reside in the namespace std. cin is typically bound to the keyboard and cout is typically bound to the screen, although files can be substituted using re-direction. To use these stream objects: 1. Include the library where they are defined: #include<iostream> 2. Resolve the namespace where they are defined: std::cin and std::cout 3. Typically work with the input and output operators >> and <<, respectively /* example use of cout with output operator */ #include <iostream> // includes library std::cout << "Hello World"; // sends string "Hello World" to screen std::cout << 'a'; // sends character 'a' to screen std::cout << x << y << z; // sends values of x, y, and z to screen, in that order /* example use of cin with input operator */ #include <iostream> // includes library std::cin >> x; // read entered value into x std::cin >> a >> b >> c; // read three entered values to a, b, c (in that order) Note that literals cannot be used on the right side of the input operator. The input operator reads data IN to a variable location: The right side of the operator must specify an Lvalue. The input operator is sometimes called the extraction operator - it "extracts" data from the input stream object and puts it into the variable. Similarly, the output operator is sometimes called the insertion operator - it "inserts" a copy of the data into the output stream object. Some people find this terminology somewhat convoluted and prefer "input/output" to "extraction/insertion". Notes on Archaic Code C++ was officially standardized in 1998, so some older code will not reflect some of the newer features. A few worth noting: "int main()" vs "void main()" the newer style is to use int as the return type on the main function, which allows one program to receive a message of success or failure (with a given error code) from another calling program. This is commonly used, for example, in operating systems processes. Note also that the version with "int main()" has a return statement at the end, returning an integer value. In this context, typically 0 is used to report success, and a variety of negative values are used to report errors. iostream vs. iostream.h The older naming convention for library header files uses.h extension. The newer style uses a different naming scheme, which is also extended to the older C libraries. Some older compilers (like Borland C++ 5.0) do not recognize or understand "using" statements and namespaces, as they pre-date the 1998 standardization. The compilers in the FSU CS student computing environment are versions of the gnu g++ compiler. They are in fairly good compliance with the C++ standard. There is also an active standards group that will soon adopt a revised standard for C++. This will present yet another target for textbook and compiler writers as this rich language evolves. 12/13

13 References The C++ Programming Language (3rd ed), Bjarne Stroustrup, Addison Wesley, C++ Primer (4th ed), by Stanley B. Lippman, Josie Lajoie, Barbara E. Moo, Addison-Wesley, /13

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

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

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Programming with C++ Language

Programming with C++ Language Programming with C++ Language Fourth stage Prepared by: Eng. Samir Jasim Ahmed Email: engsamirjasim@yahoo.com Prepared By: Eng. Samir Jasim Page 1 Introduction: Programming languages: A programming language

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

LECTURE 3 C++ Basics Part 2

LECTURE 3 C++ Basics Part 2 LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special built-in symbols that have functionality, and work on operands. Operators are actually functions that use

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

Basic Types, Variables, Literals, Constants

Basic Types, Variables, Literals, Constants Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

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

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

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

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

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

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

EEE145 Computer Programming

EEE145 Computer Programming EEE145 Computer Programming Content of Topic 2 Extracted from cpp.gantep.edu.tr Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

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

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

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More 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

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-2: Programming basics II Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428 March

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

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

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Spring 2005 Lecture 1 Jan 6, 2005 Course Information 2 Lecture: James B D Joshi Tuesdays/Thursdays: 1:00-2:15 PM Office Hours:

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

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

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

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

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

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

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

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

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

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

More 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

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Operators. Lecture 3 COP 3014 Spring January 16, 2018 Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator

More information

CSCI 1061U Programming Workshop 2. C++ Basics

CSCI 1061U Programming Workshop 2. C++ Basics CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

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

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

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers. cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... today: language basics: identifiers, data types, operators, type conversions, branching and looping, program structure

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

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

Basic Types and Formatted I/O

Basic Types and Formatted I/O Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

More 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

C++ INDEX. Introduction: Instructions for use. Basics of C++: Structure of a program Variables. Data Types. Constants Operators Basic Input/Output

C++ INDEX. Introduction: Instructions for use. Basics of C++: Structure of a program Variables. Data Types. Constants Operators Basic Input/Output INDEX Introduction: Instructions for use Basics of : Structure of a program Variables. Data Types. Constants Operators Basic Input/Output Control Structures: Control Structures Functions (I) Functions

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types ME240 Computation for Mechanical Engineering Lecture 4 C++ Data Types Introduction In this lecture we will learn some fundamental elements of C++: Introduction Data Types Identifiers Variables Constants

More information

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Information Science 1

Information Science 1 Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

More information

Introduction to C. Systems Programming Concepts

Introduction to C. Systems Programming Concepts Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

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

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols. EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

More information

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved Chapter 1 C++ Basics Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment

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

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

Expressions and Precedence. Last updated 12/10/18

Expressions and Precedence. Last updated 12/10/18 Expressions and Precedence Last updated 12/10/18 Expression: Sequence of Operators and Operands that reduce to a single value Simple and Complex Expressions Subject to Precedence and Associativity Six

More information

Programming with C++ as a Second Language

Programming with C++ as a Second Language Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

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

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

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

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

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object

More information

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words. , ean, arithmetic s s on acters Comp Sci 1570 Introduction to C++ Outline s s on acters 1 2 3 4 s s on acters Outline s s on acters 1 2 3 4 s s on acters ASCII s s on acters ASCII s s on acters Type: acter

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

Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

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++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

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

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

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

LEXICAL 2 CONVENTIONS

LEXICAL 2 CONVENTIONS LEXIAL 2 ONVENTIONS hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. ++ Programming Lexical onventions Objectives You will learn: Operators. Punctuators. omments. Identifiers. Literals. SYS-ED \OMPUTER EDUATION

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

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

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics PIC 10A Pointers, Arrays, and Dynamic Memory Allocation Ernest Ryu UCLA Mathematics Pointers A variable is stored somewhere in memory. The address-of operator & returns the memory address of the variable.

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

.Net Technologies. Components of.net Framework

.Net Technologies. Components of.net Framework .Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

More information

Tutorial-2a: First steps with C++ programming

Tutorial-2a: First steps with C++ programming Programming for Scientists Tutorial 2a 1 / 18 HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists Tutorial-2a: First steps with C++ programming Programming for

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

Divyakant Meva. Table 1. The C++ keywords

Divyakant Meva. Table 1. The C++ keywords Chapter 1 Identifiers In C/C++, the names of variables, functions, labels, and various other user-defined objects are called identifiers. These identifiers can vary from one to several characters. The

More information

This watermark does not appear in the registered version - Slide 1

This watermark does not appear in the registered version -   Slide 1 Slide 1 Chapter 1 C++ Basics Slide 2 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style

More information