C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. It runs on various platforms like Windows, Mac OS, and UNIX. The document provides an overview of key C++ concepts like basic syntax, comments, data types, variables, constants, operators, loops, functions, arrays, strings, pointers, references, structures, classes, inheritance, and input/output. It also lists common functions and their uses.
C is a general-purpose programming language initially developed for system development like operating systems. It produces efficient code nearly as fast as assembly language. The document provides an overview of basic C programming concepts including data types, variables, functions, arrays, structures, pointers, strings, input/output operations, and preprocessor directives. It also gives examples of basic "Hello World" program structure and syntax.
This document provides an introduction to the C++ programming language. It discusses that C++ was developed in 1979 as an extension of C and is an object-oriented language. It then defines various C++ concepts such as tokens, data types, variables, constants, functions, arrays, structures, and input/output streams. It provides examples of how to declare and use these different programming elements in C++ code. The document serves as a high-level overview of fundamental C++ concepts for someone new to the language.
The document outlines the course content for a C++ introductory course, including introductions to OOP concepts like classes and objects, pointers, functions, inheritance, and polymorphism. It also covers basic C++ programming concepts like I/O, data types, operators, and data structures. The course aims to provide students with fundamental C++ programming skills through explanations and examples of key C++ features.
The document provides information on the C programming language. It discusses that C was developed by Dennis Ritchie at Bell Labs in 1972 and is a general purpose programming language well suited for business and scientific applications. It describes the basic structure of a C program including sections for links, definitions, variables, functions, and input/output statements. It also covers various C language concepts like data types, operators, decision making statements, looping statements, functions, and more.
This document provides an introduction to C++ programming, covering key concepts like characters, tokens, keywords, identifiers, literals, operators, input/output, variables, comments, and common errors. It explains that C++ was created by Bjarne Stroustrup in the 1980s as an extension of C with object-oriented features from Simula 67.
C is a procedural programming language. It was developed in the early 1970s and is still widely used. The document provides an overview of key aspects of C including data types, variables, constants, operators, control statements like if/else, and functions. It also discusses C programming concepts like low-level vs high-level languages, header files, comments, escape sequences, and more. The document serves as a useful introduction and reference for someone learning the basics of the C programming language.
This document provides an introduction to the C# programming language. It discusses the objectives and structure of the first lecture, including an overview of the anatomy of a basic C# program that prints text to the console. The lecture then covers key concepts like variables, data types, arithmetic operators, input/output statements, and decision-making statements. Examples are provided to demonstrate how to write, compile, and run a simple C# program.
C is a general-purpose programming language initially developed for system development like operating systems. It produces efficient code nearly as fast as assembly language. The document provides an overview of basic C programming concepts including data types, variables, functions, arrays, structures, pointers, strings, input/output operations, and preprocessor directives. It also gives examples of basic "Hello World" program structure and syntax.
This document provides an introduction to the C++ programming language. It discusses that C++ was developed in 1979 as an extension of C and is an object-oriented language. It then defines various C++ concepts such as tokens, data types, variables, constants, functions, arrays, structures, and input/output streams. It provides examples of how to declare and use these different programming elements in C++ code. The document serves as a high-level overview of fundamental C++ concepts for someone new to the language.
The document outlines the course content for a C++ introductory course, including introductions to OOP concepts like classes and objects, pointers, functions, inheritance, and polymorphism. It also covers basic C++ programming concepts like I/O, data types, operators, and data structures. The course aims to provide students with fundamental C++ programming skills through explanations and examples of key C++ features.
The document provides information on the C programming language. It discusses that C was developed by Dennis Ritchie at Bell Labs in 1972 and is a general purpose programming language well suited for business and scientific applications. It describes the basic structure of a C program including sections for links, definitions, variables, functions, and input/output statements. It also covers various C language concepts like data types, operators, decision making statements, looping statements, functions, and more.
This document provides an introduction to C++ programming, covering key concepts like characters, tokens, keywords, identifiers, literals, operators, input/output, variables, comments, and common errors. It explains that C++ was created by Bjarne Stroustrup in the 1980s as an extension of C with object-oriented features from Simula 67.
C is a procedural programming language. It was developed in the early 1970s and is still widely used. The document provides an overview of key aspects of C including data types, variables, constants, operators, control statements like if/else, and functions. It also discusses C programming concepts like low-level vs high-level languages, header files, comments, escape sequences, and more. The document serves as a useful introduction and reference for someone learning the basics of the C programming language.
This document provides an introduction to the C# programming language. It discusses the objectives and structure of the first lecture, including an overview of the anatomy of a basic C# program that prints text to the console. The lecture then covers key concepts like variables, data types, arithmetic operators, input/output statements, and decision-making statements. Examples are provided to demonstrate how to write, compile, and run a simple C# program.
Here are the values of c in each case:
1. int a = 10, b = 2;
c = 12, 8, 20, 5
2. float a = 10, b = 2;
c = 12, 8, 20, 5
3. int a = 10; float b = 2;
c = 12, 8, 20, 5
The data types of the operands determine the result. For integer operands, the result is an integer. For floating point operands, the result is floating point.
This document discusses handling of character strings in C. It explains that a string is a sequence of characters stored in memory as ASCII codes appended with a null terminator. It describes common string operations in C like reading, displaying, concatenating, comparing and extracting substrings. It also discusses functions like strlen(), strcat(), strcmp(), strcpy() for performing various operations on strings.
The document provides an overview of the C++ programming language. It discusses that C++ was created by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. The document outlines key C++ features like classes, templates, operator overloading, and exceptions. It also covers topics like class definitions, constructors, destructors, streams, and compiling/linking C++ programs.
This document provides an overview of C++ programming concepts across multiple pages. It begins with introductions to fundamental C++ concepts like header files, compiling and linking processes, variables and data types. It then covers expressions, selection statements, loops, arrays, functions, function overloading, structures and unions. The document is intended to serve as a roadmap for learning C++.
The document discusses the Objective-C preprocessor and underlying C language features. It covers preprocessor directives like #define, #import, #include, and #undef. It also discusses arrays, structures, pointers, functions, and how Objective-C works with C at a low level. Blocks in Objective-C are described as being similar to functions but having some differences like needing to be declared in .m files instead of .h headers.
Functions allow programmers to reuse code and organize programs. There are two types of functions - library functions provided by the C standard library and user-defined functions created by the programmer. Functions improve modularity, reusability, and debuggability of large programs. Functions are declared with a return type, name, parameters, and terminator. They are defined with a header, body, local variables, statements, and return statement. Arrays allow storing multiple values of the same type and can be passed to and returned from functions. Strings are character arrays terminated by a null character. Common string functions include strcat(), strlen(), strcpy(), and strcmp().
The document outlines topics to be covered in a C programming course, including structure of C programs, identifiers, data types, constants, variables, expressions, and operators. It provides details on each topic in 3 sentences or less:
The structure of a C program consists of functions, with one function called main executing first. Functions contain a heading, argument declarations, and a compound statement enclosed in braces. Compound statements can be nested and expressions must end with semicolons.
This is Work-In-Progress. Developing a series of lectures on C++0x. This will augment my presentations on C++ and Design Pattern. First trial run was done at Interra, Noida in 2009
Embedded C is a variant of C programming language used for embedded systems. It uses a cross-compiler to convert programs into machine code for the target processor. A cross-compiler runs on one system but compiles code for another system. Pointers in embedded C store the address of a variable in memory and can be used to access the value at that address using dereference operator (*). Arrays, functions, loops and other C constructs are used similarly in embedded C to structure programs and access hardware.
This document provides an introduction to C++ for Java developers. It discusses the C++ standard and standard library, which includes containers, strings, input/output streams, and other functionality. It also covers installing compilers like GCC, compiling and running simple C++ programs, code style, using Makefiles, and includes examples of basic C++ syntax like output, input, datatypes, and strings.
This document discusses basic program elements in C++, including:
1. Initializing variables can be done in two ways - by appending an equal sign followed by the value (int a = 0), or by enclosing the value in parentheses (int a(0)). Both methods are valid in C++.
2. Variables can have either local or global scope - local variables are declared within a function while global variables are declared outside all functions.
3. Keywords are reserved words in C++ that have special meaning and cannot be used as regular identifiers. Common keywords include int, float, if, else, while, etc.
The document provides an overview of the C++ programming language. It discusses that C++ was designed by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. It outlines key C++ features such as classes, operator overloading, references, templates, exceptions, and input/output streams. It also covers topics like class definitions, constructors, destructors, friend functions, and operator overloading. The document provides examples of basic C++ programs and explains concepts like compiling, linking, and executing C++ programs.
Here is a C program to produce a spiral array as described in the task:
#include <stdio.h>
int main() {
int n = 5;
int arr[n][n];
int num = 1;
int rowBegin = 0;
int rowEnd = n-1;
int colBegin = 0;
int colEnd = n-1;
while(rowBegin <= rowEnd && colBegin <= colEnd) {
// Top row
for(int i=colBegin; i<=colEnd; i++) {
arr[rowBegin][i] = num++;
}
rowBegin++;
// Right column
for(int i=rowBegin;
The document discusses various concepts related to strings in C programming language. It defines fixed length and variable length strings. For variable length strings, it explains length controlled and delimited strings. It describes how strings are stored and manipulated in C using character arrays terminated by a null character. The document also summarizes various string manipulation functions like string length, copy, compare, concatenate etc available in C standard library.
C++ is an object-oriented programming language developed by Bjarne Stroustrup at AT&T Bell Lab in the year 1980. Initially it was named “C with classes” but later in 1983 the name changed to C++. It is an extension of C with..
This document discusses strings and regular expressions in .NET. It provides details on the System.String class and how strings are immutable. The StringBuilder class is introduced as a mutable alternative for string manipulation. Various string formatting options like standard numeric and custom format strings are covered. Finally, an overview of regular expressions is given, explaining how they provide a powerful way to parse and process text using pattern matching.
This document provides an overview of vectors in a plane including:
1) Ways to represent vectors in component form, linear form, and trigonometric form.
2) How to perform vector operations such as addition, subtraction, and scalar multiplication both graphically and algebraically.
3) Examples of finding vectors between two points, writing vectors as linear combinations of standard unit vectors, graphing vector operations, and converting between component form and trigonometric form.
Implementation details and performance traits of generics in .NET, Java and C++. Presentation for the Jerusalem .NET/C++ User Group by Sasha Goldshtein.
Here are the values of c in each case:
1. int a = 10, b = 2;
c = 12, 8, 20, 5
2. float a = 10, b = 2;
c = 12, 8, 20, 5
3. int a = 10; float b = 2;
c = 12, 8, 20, 5
The data types of the operands determine the result. For integer operands, the result is an integer. For floating point operands, the result is floating point.
This document discusses handling of character strings in C. It explains that a string is a sequence of characters stored in memory as ASCII codes appended with a null terminator. It describes common string operations in C like reading, displaying, concatenating, comparing and extracting substrings. It also discusses functions like strlen(), strcat(), strcmp(), strcpy() for performing various operations on strings.
The document provides an overview of the C++ programming language. It discusses that C++ was created by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. The document outlines key C++ features like classes, templates, operator overloading, and exceptions. It also covers topics like class definitions, constructors, destructors, streams, and compiling/linking C++ programs.
This document provides an overview of C++ programming concepts across multiple pages. It begins with introductions to fundamental C++ concepts like header files, compiling and linking processes, variables and data types. It then covers expressions, selection statements, loops, arrays, functions, function overloading, structures and unions. The document is intended to serve as a roadmap for learning C++.
The document discusses the Objective-C preprocessor and underlying C language features. It covers preprocessor directives like #define, #import, #include, and #undef. It also discusses arrays, structures, pointers, functions, and how Objective-C works with C at a low level. Blocks in Objective-C are described as being similar to functions but having some differences like needing to be declared in .m files instead of .h headers.
Functions allow programmers to reuse code and organize programs. There are two types of functions - library functions provided by the C standard library and user-defined functions created by the programmer. Functions improve modularity, reusability, and debuggability of large programs. Functions are declared with a return type, name, parameters, and terminator. They are defined with a header, body, local variables, statements, and return statement. Arrays allow storing multiple values of the same type and can be passed to and returned from functions. Strings are character arrays terminated by a null character. Common string functions include strcat(), strlen(), strcpy(), and strcmp().
The document outlines topics to be covered in a C programming course, including structure of C programs, identifiers, data types, constants, variables, expressions, and operators. It provides details on each topic in 3 sentences or less:
The structure of a C program consists of functions, with one function called main executing first. Functions contain a heading, argument declarations, and a compound statement enclosed in braces. Compound statements can be nested and expressions must end with semicolons.
This is Work-In-Progress. Developing a series of lectures on C++0x. This will augment my presentations on C++ and Design Pattern. First trial run was done at Interra, Noida in 2009
Embedded C is a variant of C programming language used for embedded systems. It uses a cross-compiler to convert programs into machine code for the target processor. A cross-compiler runs on one system but compiles code for another system. Pointers in embedded C store the address of a variable in memory and can be used to access the value at that address using dereference operator (*). Arrays, functions, loops and other C constructs are used similarly in embedded C to structure programs and access hardware.
This document provides an introduction to C++ for Java developers. It discusses the C++ standard and standard library, which includes containers, strings, input/output streams, and other functionality. It also covers installing compilers like GCC, compiling and running simple C++ programs, code style, using Makefiles, and includes examples of basic C++ syntax like output, input, datatypes, and strings.
This document discusses basic program elements in C++, including:
1. Initializing variables can be done in two ways - by appending an equal sign followed by the value (int a = 0), or by enclosing the value in parentheses (int a(0)). Both methods are valid in C++.
2. Variables can have either local or global scope - local variables are declared within a function while global variables are declared outside all functions.
3. Keywords are reserved words in C++ that have special meaning and cannot be used as regular identifiers. Common keywords include int, float, if, else, while, etc.
The document provides an overview of the C++ programming language. It discusses that C++ was designed by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. It outlines key C++ features such as classes, operator overloading, references, templates, exceptions, and input/output streams. It also covers topics like class definitions, constructors, destructors, friend functions, and operator overloading. The document provides examples of basic C++ programs and explains concepts like compiling, linking, and executing C++ programs.
Here is a C program to produce a spiral array as described in the task:
#include <stdio.h>
int main() {
int n = 5;
int arr[n][n];
int num = 1;
int rowBegin = 0;
int rowEnd = n-1;
int colBegin = 0;
int colEnd = n-1;
while(rowBegin <= rowEnd && colBegin <= colEnd) {
// Top row
for(int i=colBegin; i<=colEnd; i++) {
arr[rowBegin][i] = num++;
}
rowBegin++;
// Right column
for(int i=rowBegin;
The document discusses various concepts related to strings in C programming language. It defines fixed length and variable length strings. For variable length strings, it explains length controlled and delimited strings. It describes how strings are stored and manipulated in C using character arrays terminated by a null character. The document also summarizes various string manipulation functions like string length, copy, compare, concatenate etc available in C standard library.
C++ is an object-oriented programming language developed by Bjarne Stroustrup at AT&T Bell Lab in the year 1980. Initially it was named “C with classes” but later in 1983 the name changed to C++. It is an extension of C with..
This document discusses strings and regular expressions in .NET. It provides details on the System.String class and how strings are immutable. The StringBuilder class is introduced as a mutable alternative for string manipulation. Various string formatting options like standard numeric and custom format strings are covered. Finally, an overview of regular expressions is given, explaining how they provide a powerful way to parse and process text using pattern matching.
This document provides an overview of vectors in a plane including:
1) Ways to represent vectors in component form, linear form, and trigonometric form.
2) How to perform vector operations such as addition, subtraction, and scalar multiplication both graphically and algebraically.
3) Examples of finding vectors between two points, writing vectors as linear combinations of standard unit vectors, graphing vector operations, and converting between component form and trigonometric form.
Implementation details and performance traits of generics in .NET, Java and C++. Presentation for the Jerusalem .NET/C++ User Group by Sasha Goldshtein.
The document discusses user-defined functions in C++. It defines functions as modules that help develop and maintain large programs by breaking them into smaller pieces. Functions allow code reusability by defining blocks of code that can be invoked multiple times from different parts of a program. The document provides examples of function definitions, prototypes, calling functions by passing arguments, and defining functions that return values. It also discusses local variables, parameters, and built-in math library functions.
Object-oriented programming uses abstraction and encapsulation through abstract data types (ADTs). An ADT defines a data type and its interface independently of its implementation. This allows information hiding and modular program design. Common languages like C++, Java, and Ruby support ADTs through classes or modules, which package data with methods, support inheritance and polymorphism, and provide visibility control through private/public access specifiers. Parameterized ADTs allow a data type to work with different element types. Namespaces and packages provide separate scopes to avoid naming conflicts.
The document discusses implementing service-oriented architecture (SOA) using web services in C++. It provides reasons for using C++, such as performance advantages and tight control over memory and CPU. It then discusses how a native web services stack can help integrate legacy C++ systems and provide new capabilities without rewriting code. The stack should support web service standards, code generation from WSDL, portability, low memory usage, security, handling binary data, interoperability, and asynchronous communication. It presents the WSF/C++ stack as fulfilling these requirements through support for standards, security, low-level control, and interoperability testing.
here are some slides for introduction to C++. this slide is merely for basic understanding for C++. this powerpoint is written in Traditional Chinese(TW) and is owned by a group named "Awakening Lion" which I participate in.
Vector is a container that improves on C++ arrays by allowing elements to be added and removed dynamically without specifying a size. Vectors can hold different data types like integers, strings, and custom objects. Elements can be accessed and modified using operator[], and iterated over using begin() and end() iterators. Common operations include push_back() to add elements, pop_back() to remove the last element, and insert() and erase() to modify the elements within the vector. Vectors can be compared using ==, !=, and < to check for equality and sort order.
The document discusses file handling in C++. It describes how programs can store data permanently in files on secondary storage devices. It explains the different stream classes like ifstream, ofstream and fstream that are used for file input, output and input/output operations. It provides details on the general steps to open, use and close files. It also discusses concepts like file pointers, reading and writing data to files, and updating records in sequential access files.
Esoft Metro Campus - Programming with C++
(Template - Virtusa Corporate)
Contents:
Overview of C++ Language
C++ Program Structure
C++ Basic Syntax
Primitive Built-in types in C++
Variable types
typedef Declarations
Enumerated Types
Variable Scope
Constants/Literals
Storage Classes
Operators
Control Constructs
Functions
Math Operations in C++
Arrays
Multi-dimensional Arrays
Strings
C++ Pointers
References
Date and Time
Structures
Basic Input / Output
Classes and Objects
Inheritance
Overloading
Polymorphism
Interfaces
Files and Streams
Exception Handling
Dynamic Memory
Namespaces
Templates
Preprocessor
Multithreading
C++ functions require prototypes that specify the return type and parameters. Function overloading allows multiple functions to have the same name but different signatures. Default arguments allow functions to be called without providing trailing arguments. Inline functions expand the function body at the call site for small functions to reduce overhead compared to regular function calls.
This document discusses various data types in C programming language. It begins by defining what a data type is and then provides examples of common data types like char, int, float, and double. It explains that each data type requires a different amount of memory and has an associated range for storing values. The document then provides a table listing the typical ranges and memory requirements for each data type on a 32-bit compiler. It also includes an example C program demonstrating the usage of different data types.
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
Esoft Metro Campus - Certificate in java basics
(Template - Virtusa Corporate)
Contents:
Structure of a program
Variables & Data types
Constants
Operators
Basic Input/output
Control Structures
Functions
Arrays
Character Sequences
Pointers and Dynamic Memory
Unions
Other Data Types
Input/output with files
Searching
Sorting
Introduction to data structures
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubeykiranrajat
The document provides an overview of fundamentals of C programming including data types, identifiers, operators, input/output, type casting, precedence rules, variables scope, and preprocessors. It discusses basic data types in C like integer, floating point, and their sizes. It also covers C identifiers naming rules, keywords, arithmetic, relational, and logical operators along with their precedence.
C is a widely used programming language that is easy to learn and can create efficient programs. It allows working with low-level activities and can be compiled on many platforms. A C program consists of preprocessor commands, functions, variables, statements, expressions, and comments. A basic "Hello World" program is presented that prints the message using a printf statement.
The document is the course syllabus for C++ subject in the 2nd semester of B Sc IT program. It lists the following key topics to be covered: Function overloading, Operator overloading, Inheritance, Different forms of inheritance, Constructors and Destructors in inheritance, Virtual base class, Pointer to base class, Dynamic polymorphism, Virtual functions, Type conversions.
The document provides an introduction to programming fundamentals in C++, including basic syntax and components of a C++ program. It covers variables and data types, input/output, comments, and how to write a simple C++ program with preprocessor directives and a main function. The key topics discussed are variable declaration, fundamental data types like int, float, char, comments, and how to write a basic "Hello World" program in C++.
This document provides an introduction to the C programming language. It discusses that C was developed in 1972 by Dennis Ritchie at Bell Labs to create the UNIX operating system. C is a structured, procedural programming language that is widely used to develop operating systems, databases, networks, and more. The document then covers some key concepts in C including functions, header files, variables, data types, operators, and escape sequences. It provides examples of basic C programs and exercises for practicing programming concepts.
The document provides an introduction to the C++ programming language, including its history, characteristics, and components. It notes that C++ was created in the 1980s by Bjarne Stroustrup at Bell Labs as an enhancement to the C language that added object-oriented programming capabilities while still maintaining efficiency. Some key characteristics of C++ include object-oriented programming, portability, modular programming, C compatibility, and a wide range of library functions. The document discusses the basic building blocks of C++, including tokens like identifiers, keywords, constants, punctuators, and operators.
The document provides an overview of ASP.NET including:
- It was developed by Microsoft to create web and desktop applications that run on Windows.
- It includes frameworks, class libraries, languages and tools to develop web and desktop applications.
- Programming languages that can be used to build applications include WinForms, ASP.NET and ADO.NET.
The document discusses header files and C preprocessors. It defines header files as files containing C declarations and macro definitions that can be shared between source files by including them using the #include directive. Common header files like stdio.h, conio.h, and math.h are given as examples. Preprocessors are described as a macro processor that transforms the program before compilation by handling preprocessor directives like #define. It allows defining macros which are abbreviations for longer code constructs. The document also provides examples of preprocessor directives like #include and #define.
This document provides an introduction to programming with C++, including comments, data types, variables, arithmetic operators, and expressions. It discusses single-line and multi-line comments to document code. The fundamental C++ data types are integer, floating point, and character, each with different size ranges. Variables are declared with a data type and assigned values. Arithmetic operators allow mathematical expressions to be evaluated using precedence rules. Relational operators enable boolean expressions.
The document provides information about C and C Sharp programming languages. It discusses the history, features, data types, loops, conditional statements, functions, arrays, pointers, object-oriented concepts like inheritance, encapsulation, polymorphism in both the languages. It also highlights some advantages of C Sharp over C like automatic memory management, no need of header files etc.
This document provides an overview of the C++ programming language. It discusses key C++ concepts like classes, objects, functions, and data types. Some key points:
- C++ is an object-oriented language that is an extension of C with additional features like classes and inheritance.
- Classes allow programmers to combine data and functions to model real-world entities. Objects are instances of classes.
- The document defines common C++ terms like keywords, identifiers, constants, and operators. It also provides examples of basic programs.
- Functions are described as modular and reusable blocks of code. Parameter passing techniques like pass-by-value and pass-by-reference are covered.
- Other concepts covered include
C# is an object-oriented programming language where all program logic must be contained within classes. It has features like garbage collection, inheritance, interfaces, namespaces, and data types similar to Java. Key concepts include value types vs reference types, boxing and unboxing, arrays, enums, structs, and parameter passing modes like pass by value, reference, and output. The language has control structures like if/else, switch, while, for, and foreach loops to control program flow. Methods can be instance methods or static methods.
This document discusses object oriented programming concepts in C++ including string handling, copy constructors, polymorphism, and dynamic memory allocation. It provides examples of:
1) Using string class functions like append(), find(), length(), replace(), and swap() as well as string operators like =, +, +=, ==, <, and >.
2) Defining and using a copy constructor to initialize an object using another object of the same class.
3) Compile-time polymorphism through function and operator overloading allowing functions or operators to work with multiple types.
4) Dynamic memory allocation using new and delete to allocate and free memory for objects at runtime rather than compile-time.
#Code2Create series: C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports different ways of programming like procedural, object-oriented, functional, and so on.Start your programming journey and join us to learn C++ basics!
by Google Developers Group and Women Tech-markers Kuwait chapter:
Instagram and Twitter: @GDGWTMKUWAIT
The document discusses various operators in C++ including arithmetic, increment/decrement, assignment, relational, logical, and bitwise operators. It also covers topics such as loops, arrays, functions, pointers, classes, and objects. Key operators and concepts covered include addition, subtraction, multiplication, division, increment, decrement, assignment, comparison, logical AND/OR/NOT, bitwise AND/OR/XOR/complement, for/while/do-while loops, one and two dimensional arrays, user-defined and recursive functions, regular and double pointers, dynamic memory allocation, and the basics of classes and objects in C++.
2. History
• C++ is a middle-level programming language
developed by Bjarne Stroustrup starting in
1979 at Bell Labs. C++ runs on a variety of
platforms, such as Windows, Mac OS, and the
various versions of UNIX.
3. Summary
• C++ Overview
• C++ Environment Setup
• C++ Basic Syntax
• C++ Comments
• C++ Data Types
• C++ Variable Types
• C++ Variable Scope
• C++ Constants/Literals
• C++ Modifier Types
• C++ Storage Classes
• C++ Operators
• C++ Loop Types
• C++ Decision Making
• C++ Functions
• C++ Numbers
• C++ Arrays
• C++ Strings
• C++ Pointers
• C++ References
• C++ Date & Time
• C++ Basic Input/Output
• C++ Data Structures
• C++ Object Oriented
• C++ Classes & Objects
• C++ Inheritance
• C++ Overloading
• C++ Polymorphism
• C++ Abstraction
• C++ Encapsulation
• C++ Interfaces
• C++ Advanced
• C++ Files and Streams
• C++ Exception Handling
• C++ Dynamic Memory
• C++ Namespaces
• C++ Templates
• C++ Preprocessor
• C++ Signal Handling
• C++ Multithreading
• C++ Web Programming
4. Entry Point of the program
#include <iostream>
using namespace std;
int main()
{ cout << "Hello World"; return 0; }
5. Basic Syntax
• Object - Objects have states and behaviors. Example: A dog
has states - color, name, breed as well as behaviors -
wagging, barking, eating. An object is an instance of a class.
• Class - A class can be defined as a template/blueprint that
describes the behaviors/states that object of its type
support.
• Methods - A method is basically a behavior. A class can
contain many methods. It is in methods where the logics
are written, data is manipulated and all the actions are
executed.
• Instance Variables - Each object has its unique set of
instance variables. An object's state is created by the values
assigned to these instance variables.
6. Basic Syntax
• Semicolons & Blocks in C++
• C++ Identifiers
• C++ Keywords
• Trigraphs
• Whitespace in C++
7. Comments
• C++ supports single-line and multi-line comments. All
characters available inside any comment are ignored by
C++ compiler.
• C++ comments start with /* and end with */. For
example:
• /* This is a comment */ /* C++ comments can also *
span multiple lines */A comment can also start with //,
extending to the end of the line. For example:
• #include <iostream> using namespace std; main() {
cout << "Hello World"; // prints Hello World return 0; }
9. Variable Type
• Variable Definition
• Variable Declaration
• Lvalues and Rvalues
– lvalue : Expressions that refer to a memory location is
called "lvalue" expression. An lvalue may appear as
either the left-hand or right-hand side of an
assignment.
– rvalue : The term rvalue refers to a data value that is
stored at some address in memory. An rvalue is an
expression that cannot have a value assigned to it
which means an rvalue may appear on the right- but
not left-hand side of an assignment.
10. Variable Scope
• Local Variables
• Global Variables
• Initializing Local and Global Variables
– you must initialize
11. Constants/Literals
• Integer literals
• Floating-point literals
• Boolean literals
• Character literals
• String literals
• Defining Constants:
• There are two simple ways in C++ to define
constants:
– Using #define preprocessor.
– Using const keyword.
12. Modifier Types
• The data type modifiers are listed here:
– signed
– unsigned
– long
– Short
13. • Type Qualifiers
– Qualifier
– Meaning
– const
– Objects of type const cannot be changed by your program
during execution
– volatile
– The modifier volatile tells the compiler that a variable's value
may be changed in ways not explicitly specified by the program.
– restrict
– A pointer qualified by restrict is initially the only means by
which the object it points to can be accessed. Only C99 adds a
new type qualifier called restrict.
14. Storage Classes
• A storage class defines the scope (visibility) and
life-time of variables and/or functions within a
C++ Program. These specifiers precede the type
that they modify. There are following storage
classes, which can be used in a C++ Program
– auto
– register
– static
– extern
– mutable
15. Operators
• An operator is a symbol that tells the compiler to
perform specific mathematical or logical
manipulations. C++ is rich in built-in operators
and provides the following types of operators:
– Arithmetic Operators
– Relational Operators
– Logical Operators
– Bitwise Operators
– Assignment Operators
– Misc Operators
16. Loop Types
Loop Type Description
while loop Repeats a statement or group of statements
while a given condition is true. It tests the
condition before executing the loop body.
for loop Execute a sequence of statements multiple times
and abbreviates the code that manages the loop
variable.
do...while loop Like a while statement, except that it tests the
condition at the end of the loop body
nested loops You can use one or more loop inside any another
while, for or do..while loop.
17. Loop Types
Control Statement Description
break statement Terminates the loop or switch statement and
transfers execution to the statement
immediately following the loop or switch.
continue statement Causes the loop to skip the remainder of its body
and immediately retest its condition prior to
reiterating.
goto statement Transfers control to the labeled statement.
Though it is not advised to use goto statement in
your program.
18. Decision making statements
Statement Description
if statement An if statement consists of a boolean
expression followed by one or more
statements.
if...else statement An if statement can be followed by an
optional else statement, which executes
when the boolean expression is false.
switch statement A switch statement allows a variable to be
tested for equality against a list of values.
nested if statements You can use one if or else if statement inside
another if or else if statement(s).
nested switch
statements
You can use one swicth statement inside
another switch statement(s).
19. Decision Making
• The ? : Operator:
• We have covered conditional operator ? : in
previous chapter which can be used to
replaceif...else statements. It has the
following general form:
• Exp1 ? Exp2 : Exp3;
20. Functions
• Defining a Function:
– The general form of a C++ function definition is as
follows:
return_type function_name( parameter list ) {
body of the function }
21. • Function Declarations:
• A function declaration tells the compiler
about a function name and how to call the
function. The actual body of the function can
be defined separately.
• A function declaration has the following parts:
• return_type function_name( parameter list );
22. • Calling a Function:
• While creating a C++ function, you give a
definition of what the function has to do. To
use a function, you will have to call or invoke
that function.
23. Function Arguments
Call Type Description
Call by value This method copies the actual value of an
argument into the formal parameter of the
function. In this case, changes made to the
parameter inside the function have no effect on
the argument.
Call by pointer This method copies the address of an argument
into the formal parameter. Inside the function,
the address is used to access the actual
argument used in the call. This means that
changes made to the parameter affect the
argument.
Call by reference This method copies the reference of an
argument into the formal parameter. Inside the
function, the reference is used to access the
actual argument used in the call. This means
that changes made to the parameter affect the
argument.
24. Numbers
• Defining Numbers in C++:
• You have already defined numbers in various examples
given in previous chapters. Here is another consolidated
example to define various types of numbers in C++:
• #include <iostream> using namespace std; int main () { //
number definition: short s; int i; long l; float f; double d; //
number assignments; s = 10; i = 1000; l = 1000000; f =
230.47; d = 30949.374; // number printing; cout << "short s
:" << s << endl; cout << "int i :" << i << endl; cout << "long l
:" << l << endl; cout << "float f :" << f << endl; cout <<
"double d :" << d << endl; return 0; }
• Math Operations
• Random Numbers
25. Arrays
• data structure, the array, which stores a fixed-
size sequential collection of elements of the
same type. Declaring Arrays:
• To declare an array in C++, the programmer
specifies the type of the elements and the
number of elements required by an array as
follows:
• type arrayName [ arraySize ];
26. Arrays
• Initializing Arrays:
• You can initialize C++ array elements either
one by one or using a single statement as
follows:
• double balance[5] = {1000.0, 2.0, 3.4, 17.0,
50.0};
double balance[] = {1000.0, 2.0, 3.4, 17.0,
50.0};
• balance[4] = 50.0;
27. Array in Detail
Concept Description
Multi-dimensional arrays C++ supports multidimensional arrays.
The simplest form of the
multidimensional array is the two-
dimensional array.
Pointer to an array You can generate a pointer to the first
element of an array by simply specifying
the array name, without any index.
Passing arrays to functions You can pass to the function a pointer to
an array by specifying the array's name
without an index.
Return array from
functions
C++ allows a function to return an array.
28. Strings
• C++ provides following two types of string
representations:
• The C-style character string.
• The string class type introduced with Standard
C++.
29. C-Style
• char greeting[6] = {'H', 'e', 'l', 'l', 'o', '0'};If you
follow the rule of array initialization, then you
can write the above statement as follows:
• char greeting[] = "Hello";
31. String Functions
S.
N
.
Function & Purpose
1 strcpy(s1, s2);Copies string s2 into string s1.
2 strcat(s1, s2);Concatenates string s2 onto the end of string s1.
3 strlen(s1);Returns the length of string s1.
4 strcmp(s1, s2);Returns 0 if s1 and s2 are the same; less than 0 if
s1<s2; greater than 0 if s1>s2.
5 strchr(s1, ch);Returns a pointer to the first occurrence of character
ch in string s1.
6 strstr(s1, s2);Returns a pointer to the first occurrence of string s2 in
string s1.
32. Pointers
• A pointer is a variable whose value is the
address of another variable. Like any variable
or constant, you must declare a pointer before
you can work with it.
– int *ip; // pointer to an integer
– double *dp; // pointer to a double
– float *fp; // pointer to a float
– char *ch // pointer to character
33. Pointer Details
Concept Description
C++ Null Pointers C++ supports null pointer, which is a
constant with a value of zero defined in
several standard libraries.
C++ pointer arithmetic There are four arithmetic operators that
can be used on pointers: ++, --, +, -
C++ pointers vs arrays There is a close relationship between
pointers and arrays. Let us check how?
C++ array of pointers You can define arrays to hold a number
of pointers.
C++ pointer to pointer C++ allows you to have pointer on a
pointer and so on.
Passing pointers to
functions
Passing an argument by reference or by
address both enable the passed
argument to be changed in the calling
function by the called function.
Return pointer from
functions
C++ allows a function to return a pointer
to local variable, static variable and
dynamically allocated memory as well.
34. References
• References are often confused with pointers but
three major differences between references and
pointers are:
– You cannot have NULL references. You must always be
able to assume that a reference is connected to a
legitimate piece of storage.
– Once a reference is initialized to an object, it cannot
be changed to refer to another object. Pointers can be
pointed to another object at any time.
– A reference must be initialized when it is created.
Pointers can be initialized at any time.
35. Creating References
• int i = 17;We can declare reference variables
for i as follows.
• int& r = i;
Concept Description
References as parameters C++ supports passing references as
function parameter more safely than
parameters.
Reference as return value You can return reference from a C++
function like a any other data type can be
returned.
36. Time and Date
• struct tm {
int tm_sec; // seconds of minutes from 0 to 61
int tm_min; // minutes of hour from 0 to 59
int tm_hour; // hours of day from 0 to 24 int
tm_mday; // day of month from 1 to 31 int
tm_mon; // month of year from 0 to 11 int
tm_year; // year since 1900
int tm_wday; // days since sunday
int tm_yday; // days since January 1st
int tm_isdst; // hours of daylight savings time }
37. Basic Input/Output
Header File Function and Description
<iostream> This file defines the cin, cout, cerr and clog objects,
which correspond to the standard input stream, the
standard output stream, the un-buffered standard error
stream and the buffered standard error stream,
respectively.
<iomanip> This file declares services useful for performing
formatted I/O with so-called parameterized stream
manipulators, such as setw and setprecision.
<fstream> This file declares services for user-controlled file
processing. We will discuss about it in detail in File and
Stream related chapter.
38. • The standard output stream (cout)
– <<
• The standard input stream (cin)
– >>
• The standard error stream (cerr)
• The standard log stream (clog)
39. Data Structures
• Structures are used to represent a record,
suppose you want to keep track of your books
in a library. You might want to track the
following attributes about each book:
– Title
– Author
– Subject
– Book ID
40. Structure
• Defining a Structure:
• To define a structure, you must use the struct
statement. The struct statement defines a new
data type, with more than one member, for
your program. The format of the struct
statement is this:
• struct [structure tag] { member definition;
member definition; ... member definition; }
[one or more structure variables];
43. Structure
• Pointers to Structures:
• You can define pointers to structures in very similar way as
you define pointer to any other variable as follows:
• struct Books *struct_pointer;Now, you can store the
address of a structure variable in the above defined pointer
variable. To find the address of a structure variable, place
the & operator before the structure's name as follows:
• struct_pointer = &Book1;To access the members of a
structure using a pointer to that structure, you must use
the -> operator as follows:
• struct_pointer->title;
44. typedef
• The typedef Keyword
• There is an easier way to define structs or you
could "alias" types you create. For example:
• typedef struct { char title[50]; char author[50];
char subject[100]; int book_id; }Books;Now,
you can use Books directly to define variables
of Books type without using struct keyword.
Following is the example:
• Books Book1, Book2;
45. Class
• class Box { public: double length; // Length of
a box double breadth; // Breadth of a box
double height; // Height of a box };
46. Define Objects
• Define C++ Objects:
• A class provides the blueprints for objects, so
basically an object is created from a class. We
declare objects of a class with exactly the
same sort of declaration that we declare
variables of basic types. Following statements
declare two objects of class Box:
• Box Box1; // Declare Box1 of type Box Box
Box2; // Declare Box2 of type Box
47. Accessing the Data Members
• The public data members of objects of a class
can be accessed using the direct member
access operator (.).
48. Class Details
Concept Description
Class member functions A member function of a class is a function that has its definition or its prototype within the class definition like any
other variable.
Class access modifiers A class member can be defined as public, private or protected. By default members would be assumed as private.
Constructor & destructor A class constructor is a special function in a class that is called when a new object of the class is created. A destructor
is also a special function which is called when created object is deleted.
C++ copy constructor The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which
has been created previously.
C++ friend functions A friend function is permitted full access to private and protected members of a class.
C++ inline functions With an inline function, the compiler tries to expand the code in the body of the function in place of a call to the
function.
The this pointer in C++ Every object has a special pointer this which points to the object itself.
Pointer to C++ classes A pointer to a class is done exactly the same way a pointer to a structure is. In fact a class is really just a structure with
functions in it.
Static members of a class Both data members and function members of a class can be declared as static.
49. Classes & Objects
• Inheritance
– Inheritance allows us to define a class in terms of
another class
• Overloading
– specify more than one definition for
a function name or an operator in the same scope
• Polymorphism
– occurs when there is a hierarchy of classes and
they are related by inheritance.
50. Classes & Objects
• Abstraction
– providing only essential information to the outside world and
hiding their background details
• Encapsulation
– an Object Oriented Programming concept that binds together
the data and functions that manipulate the data, and that keeps
both safe from outside interference and misuse. Data
encapsulation led to the important OOP concept of data hiding.
• Interfaces
– implemented using abstract classes and these abstract classes
should not be confused with data abstraction which is a concept
of keeping implementation details separate from associated
data
51. Inheritances
• class derived-class: access-specifier base-class
Base & Derived Classes
– Public
– Protected
– Private
Access public protected private
Same class yes yes yes
Derived classes yes yes no
Outside classes yes no no
52. Inheritances
• Multiple Inheritances:
• A C++ class can inherit members from more
than one class and here is the extended
syntax:
• class derived-class: access baseA, access
baseB....
54. Polymorphism
• a call to a member function will cause a
different function to be executed depending
on the type of object that invokes the function
• Call to area defined in shape for difference
classes like rectangle Triangle, etc…
55. • Virtual Function:
– A virtual function is a function in a base class that
is declared using the keyword virtual.
• Pure Virtual Functions:
– It's possible that you'd want to include a virtual
function in a base class so that it may be redefined
in a derived class to suit the objects of that class,
but that there is no meaningful definition you
could give for the function in the base class.
57. Interfaces
• A class is made abstract by declaring at least
one of its functions as pure virtual function. A
pure virtual function is specified by placing "=
0“
• an abstract class (often referred to as an ABC)
is to provide an appropriate base class from
which other classes can inherit. Abstract
classes cannot be used to instantiate objects
and serves only as an interface.
59. Files and Streams
Data Type Description
ofstream This data type represents the output file stream
and is used to create files and to write
information to files.
ifstream This data type represents the input file stream
and is used to read information from files.
fstream This data type represents the file stream
generally, and has the capabilities of both
ofstream and ifstream which means it can create
files, write information to files, and read
information from files.
61. Exception Handing
• Exceptions provide a way to transfer control
from one part of a program to another. C++
exception handling is built upon three
keywords: try, catch, and throw.
62. Dynamic Memory
• Memory in your C++ program is divided into
two parts:
– The stack: All variables declared inside the
function will take up memory from the stack.
– The heap: This is unused memory of the program
and can be used to allocate the memory
dynamically when program runs.
• The new and delete operators
63. Dynamic Memory for Arrays
• char* pvalue = NULL; // Pointer initialized with
null pvalue = new char[20]; // Request
memory for the variableTo remove the array
that we have just created the statement
would look like this:
• delete [] pvalue; // Delete array pointed to by
pvalueFollowing is the syntax of new operator
for a multi-dimensional array as follows:
64. Dynamic Memory for Arrays
• int ROW = 2; int COL = 3; double **pvalue =
new double* [ROW]; // Allocate memory for
rows // Now allocate memory for columns
for(int i = 0; i < COL; i++) { pvalue[i] = new
double[COL]; }The syntax to release the
memory for multi-dimensional will be as
follows:
• for(int i = 0; i < COL; i++) { delete[] pvalue[i]; }
delete [] pvalue;
65. Dynamic Memory for Objects
• #include <iostream> using namespace std;
class Box { public: Box() { cout << "Constructor
called!" <<endl; } ~Box() { cout << "Destructor
called!" <<endl; } }; int main( ) { Box*
myBoxArray = new Box[4]; delete []
myBoxArray; // Delete array return 0; }
66. Namespace
• A namespace is designed to overcome this
difficulty and is used as additional information
to differentiate similar functions, classes,
variables etc. with the same name available in
different libraries. Using namespace, you can
define the context in which names are
defined. In essence, a namespace defines a
scope.
• Nested namespaces
67. Namespace
• A namespace definition begins with the
keyword namespace followed by the
namespace name as follows:
• namespace namespace_name { // code
declarations }To call the namespace-enabled
version of either function or variable, prepend
the namespace name as follows:
• name::code; // code could be variable or
function.
68. Templates
• Templates are the foundation of generic programming,
which involves writing code in a way that is independent of
any particular type
• Function Template:
• The general form of a template function definition is shown
here:
• template <class type> ret-type func-name(parameter list) {
// body of function }
• Class Template:
• Just as we can define function templates, we can also
define class templates. The general form of a generic class
declaration is shown here:
• template <class type> class class-name { . . . }
69. Preprocessor
• The #define preprocessor directive creates
symbolic constants. The symbolic constant is
called a macro and the general form of the
directive is:
• #define macro-name replacement-text
70. Signal Handling
• Signals are the interrupts delivered to a
process by the operating system which can
terminate a program prematurely.
Signal Description
SIGABRT Abnormal termination of the program, such as a call
to abort
SIGFPE An erroneous arithmetic operation, such as a divide by
zero or an operation resulting in overflow.
SIGILL Detection of an illegal instruction
SIGINT Receipt of an interactive attention signal.
SIGSEGV An invalid access to storage.
SIGTERM A termination request sent to the program.
71. Signal Function
• The signal() function:
• C++ signal-handling library provides
function signal to trap unexpected events.
Following is the syntax of the signal() function:
• void (*signal (int sig, void (*func)(int)))(int);
72. Multithreading
• specialized form of multitasking and a
multitasking is the feature that allows your
computer to run two or more programs
concurrently
• There is following routine which we use to
create a POSIX thread:
• #include <pthread.h> pthread_create (thread,
attr, start_routine, arg)
73. Threading
Parameter Description
thread An opaque, unique identifier for the new thread
returned by the subroutine.
attr An opaque attribute object that may be used to set
thread attributes. You can specify a thread attributes
object, or NULL for the default values.
start_routine The C++ routine that the thread will execute once it
is created.
arg A single argument that may be passed to
start_routine. It must be passed by reference as a
pointer cast of type void. NULL may be used if no
argument is to be passed.
74. Threading
• Terminating Threads:
• There is following routine which we use to
terminate a POSIX thread:
• #include <pthread.h> pthread_exit (status)
75. Threading
• #include <iostream> #include <cstdlib> #include <pthread.h> using
namespace std; #define NUM_THREADS 5 struct thread_data{ int
thread_id; char *message; }; void *PrintHello(void *threadarg) {
struct thread_data *my_data; my_data = (struct thread_data *)
threadarg; cout << "Thread ID : " << my_data->thread_id ; cout << "
Message : " << my_data->message << endl; pthread_exit(NULL); }
int main () { pthread_t threads[NUM_THREADS]; struct thread_data
td[NUM_THREADS]; int rc; int i; for( i=0; i < NUM_THREADS; i++ ){
cout <<"main() : creating thread, " << i << endl; td[i].thread_id = i;
td[i].message = "This is message"; rc = pthread_create(&threads[i],
NULL, PrintHello, (void *)&td[i]); if (rc){ cout << "Error:unable to
create thread," << rc << endl; exit(-1); } } pthread_exit(NULL); }
76. Threading
• #include <iostream> #include <cstdlib> #include <pthread.h> #include
<unistd.h> using namespace std; #define NUM_THREADS 5 void
*wait(void *t) { int i; long tid; tid = (long)t; sleep(1); cout << "Sleeping in
thread " << endl; cout << "Thread with id : " << tid << " ...exiting " << endl;
pthread_exit(NULL); } int main () { int rc; int i; pthread_t
threads[NUM_THREADS]; pthread_attr_t attr; void *status; // Initialize
and set thread joinable pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for(
i=0; i < NUM_THREADS; i++ ){ cout << "main() : creating thread, " << i <<
endl; rc = pthread_create(&threads[i], NULL, wait, (void *)i ); if (rc){ cout
<< "Error:unable to create thread," << rc << endl; exit(-1); } } // free
attribute and wait for the other threads pthread_attr_destroy(&attr); for(
i=0; i < NUM_THREADS; i++ ){ rc = pthread_join(threads[i], &status); if (rc){
cout << "Error:unable to join," << rc << endl; exit(-1); } cout << "Main:
completed thread id :" << i ; cout << " exiting with status :" << status <<
endl; } cout << "Main: program exiting." << endl; pthread_exit(NULL); }