The document provides an overview of basic concepts in C++ including identifiers, keywords, data types, variables, constants, operators, and input/output. It discusses identifiers and keywords, the fundamental data types in C++ including integer, floating point, boolean, character, and strings. It covers declaring and initializing variables, the scope of variables, and different types of constants like literals, defined constants, and declared constants. It also provides examples of using the assignment operator and operators can be used as part of expressions.
The document provides an overview of key concepts in C++ programming, including:
- Functions break programs into small pieces that perform specific tasks.
- Variables store and represent data that can change, like integers and characters.
- Comments are used to explain source code and are ignored by the compiler.
- Data types like int, float, char and bool determine what kind of data a variable can hold.
- Operators perform actions like arithmetic calculations and assignment.
- Libraries contain precompiled functions that can be used across programs.
This presentation comes with many additional notes (pdf): http://de.slideshare.net/nicolayludwig/2-cpp-imperative-programming-38499061
Check out these exercises: http://de.slideshare.net/nicolayludwig/2-cpp-imperative-programmingexercises
- Imperative Programming
- Style and Conventions
- Constants
- Fundamental Types
- Console Basics
- Operators, Precedence, Associativity and Evaluation Order
- Control Structures and Blocks
This document provides an overview of C++ programming fundamentals. It discusses two main categories of software: system software and application software. It then introduces the C language, covering its history, evolution, and justification. The document also examines the development environment for C, including tools like editors, compilers, debuggers, and integrated development environments. It provides examples of basic C++ programs and explains the parts and structure of a C++ program.
C++ Programming Language Training in Ambala ! Batra Computer Centrejatin batra
Batra Computer Centre is An ISO certified 9001:2008 training Centre in Ambala.
We Provide C++ Programming Language Training in Ambala. BATRA COMPUTER CENTRE provides best training in C, C++, S.E.O, Web Designing, Web Development and So many other courses are available.
This document defines and explains the basic tokens in C++ programming, including keywords, variables, constants, escape sequences, and operators. Keywords are predefined reserved words with special meanings. Variables are used to store and manipulate data. Constants cannot change value during program execution. Escape sequences represent special characters. Operators specify operations on operands and include arithmetic, relational, logical, and assignment operators.
C++ programming program design including data structures Ahmad Idrees
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
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.
The document provides an overview of the C++ programming language, including:
- A brief history of C++ and how it was developed based on C while incorporating object-oriented programming features.
- Descriptions of key computer science concepts like hardware, memory, data types, compilers, and the software development process.
- Explanations of core C++ programming concepts like variables, data types, operators, expressions, and identifiers. It also discusses object-oriented features and the standard libraries.
- Short sections on C++ keywords, tokens, structures, advantages and disadvantages.
So in summary, the document introduces the C++ language by covering its origins and evolution, underlying computer science principles, and
The document provides an overview of key concepts in C++ programming, including:
- Functions break programs into small pieces that perform specific tasks.
- Variables store and represent data that can change, like integers and characters.
- Comments are used to explain source code and are ignored by the compiler.
- Data types like int, float, char and bool determine what kind of data a variable can hold.
- Operators perform actions like arithmetic calculations and assignment.
- Libraries contain precompiled functions that can be used across programs.
This presentation comes with many additional notes (pdf): http://de.slideshare.net/nicolayludwig/2-cpp-imperative-programming-38499061
Check out these exercises: http://de.slideshare.net/nicolayludwig/2-cpp-imperative-programmingexercises
- Imperative Programming
- Style and Conventions
- Constants
- Fundamental Types
- Console Basics
- Operators, Precedence, Associativity and Evaluation Order
- Control Structures and Blocks
This document provides an overview of C++ programming fundamentals. It discusses two main categories of software: system software and application software. It then introduces the C language, covering its history, evolution, and justification. The document also examines the development environment for C, including tools like editors, compilers, debuggers, and integrated development environments. It provides examples of basic C++ programs and explains the parts and structure of a C++ program.
C++ Programming Language Training in Ambala ! Batra Computer Centrejatin batra
Batra Computer Centre is An ISO certified 9001:2008 training Centre in Ambala.
We Provide C++ Programming Language Training in Ambala. BATRA COMPUTER CENTRE provides best training in C, C++, S.E.O, Web Designing, Web Development and So many other courses are available.
This document defines and explains the basic tokens in C++ programming, including keywords, variables, constants, escape sequences, and operators. Keywords are predefined reserved words with special meanings. Variables are used to store and manipulate data. Constants cannot change value during program execution. Escape sequences represent special characters. Operators specify operations on operands and include arithmetic, relational, logical, and assignment operators.
C++ programming program design including data structures Ahmad Idrees
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
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.
The document provides an overview of the C++ programming language, including:
- A brief history of C++ and how it was developed based on C while incorporating object-oriented programming features.
- Descriptions of key computer science concepts like hardware, memory, data types, compilers, and the software development process.
- Explanations of core C++ programming concepts like variables, data types, operators, expressions, and identifiers. It also discusses object-oriented features and the standard libraries.
- Short sections on C++ keywords, tokens, structures, advantages and disadvantages.
So in summary, the document introduces the C++ language by covering its origins and evolution, underlying computer science principles, and
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
C++ is an object-oriented programming language that is based on C and adds object-oriented programming features like classes, inheritance, and polymorphism. It was created by Bjarne Stroustrup at Bell Labs in the early 1980s. The document provides an introduction to C++ including its history, differences from C, program structure, data types, variables, input/output, and integrated development environments.
C++ is an object-oriented programming language that is an extension of C. It was developed in the 1980s to support object-oriented programming. In C++, data and functions can be combined into objects. Data in an object can only be accessed by the object's functions, allowing for encapsulation. The document then provides an overview of key C++ concepts like data types, tokens, operators, and input/output streams to introduce basic C++ syntax and programming.
45 Days C++ Programming Language Training in Ambalajatin batra
Are you looking for C++Programming Training In Ambala?
Now you search ends here... Batra Computer Centre provides you best C++ Programming Language Training in Ambala Cantt. We also proides you training in C, HTML, PHP, Web Designing, Web Development, SEO, SMO also.
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.
C++ is an object-oriented programming language that is considered intermediate-level as it includes both high-level and low-level features. It was initially called 'C with Classes' but was renamed to C++ in 1983. C++ was created in the early 1980s at Bell Labs by Bjarne Stroustrup and is based on the C language. C++ is called an object-oriented language because it views problems in terms of objects rather than procedures. Key concepts of object-oriented programming in C++ include classes, objects, data abstraction, encapsulation, polymorphism, and inheritance.
Learning C++ - Introduction to c++ programming 1Ali Aminian
This document provides an introduction to C++ programming, covering key concepts like the workspace, basics of the C++ environment, data types, and operations. It discusses setting up a Microsoft Visual Studio workspace and comments. The basics section explains preprocessor directives, header files, the main function framework, and input/output streams. Data types covered include integers, floating point, Boolean, characters, and enums. Operations explained are conditionals, loops like for and while, and logical/comparison operators. The document aims to familiarize readers with fundamental C++ concepts.
Keywords, identifiers ,datatypes in C++Ankur Pandey
Everything about Keywords, Identifiers,
Datatypes in C++, in this module you gain knowledge about what is Keywords, Identifiers,
Datatypes in C++ (Object oriented programming).
This document provides information about C++ programming language tokens and input/output operations. It defines various tokens like keywords, identifiers, literals, punctuators, and operators. It explains the basic structure of a C++ program and defines important headers like iostream. It also describes input/output streams like cout and cin, and input/output operators like << and >>.
The document discusses various C++ data types including built-in types like int and float, user-defined types like structures and classes, and derived types like arrays and pointers. It also covers constants, control structures for selection and loops, and the differences between constants, constant pointers, and pointers to constants.
This document provides an overview of C++ programming concepts including:
- Procedure-oriented programming focuses on tasks like reading, calculating and printing using functions, while object-oriented programming emphasizes data through objects and classes.
- C++ was developed to include object-oriented features while retaining C's simplicity, with classes, inheritance, and other features enabling abstract data types.
- Key concepts covered include classes, objects, member functions, inline functions, passing objects as parameters, returning objects, arrays of objects, and function overloading. Examples are provided to illustrate each concept.
This document discusses various C++ concepts including tokens, keywords, identifiers, constants, data types, user-defined data types like struct, union, enum, and class. It also covers derived data types like arrays, functions, and pointers. It provides examples and programs to demonstrate struct, union, enum, functions, pointers, and references. The document is a set of lecture notes that serves as an introduction to fundamental C++ programming concepts.
This document provides an introduction to C++ programming, covering key concepts like characters, tokens, keywords, identifiers, literals, operators, I/O streams, variables, comments, and common errors. It explains that Bjarne Stroustrup extended C to create C++, adding object-oriented features from Simula. The main components discussed are the building blocks of any C++ program - characters, tokens, data types, and basic input/output operations.
C Tokens, Escape sequence, Delimiters, Variables, Data types, Constants/ Literals, Expressions, Statements and Comments
https://github.com/ashim888/csit-c
This document summarizes Chapter 2 of a C++ basics textbook. Section 2.1 discusses variables and assignments, including declaring variables, assigning values, and keywords. Section 2.2 covers input and output streams like cout and cin. Section 2.3 reviews data types like int, double, char, and bool, and arithmetic expressions.
This document discusses different data types in C/C++ including character, integer, and real (float) data types. It explains that character data can be signed or unsigned and occupies 1 byte, integer data represents whole numbers using the int type, and float data represents decimal numbers. The document also covers numeric and non-numeric constants in C/C++ such as integer, octal, hexadecimal, floating point, character, and string constants.
This document provides an overview of C++ data types. It discusses fundamental data types like integer, character, float, and double. It also covers type modifiers, derived data types like arrays and functions, and other concepts like pointers, references, constants, classes, structures, unions, and enumerations. The document aims to explain the different data types and how they are used in C++.
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
C++ is an object-oriented programming language that is based on C and adds object-oriented programming features like classes, inheritance, and polymorphism. It was created by Bjarne Stroustrup at Bell Labs in the early 1980s. The document provides an introduction to C++ including its history, differences from C, program structure, data types, variables, input/output, and integrated development environments.
C++ is an object-oriented programming language that is an extension of C. It was developed in the 1980s to support object-oriented programming. In C++, data and functions can be combined into objects. Data in an object can only be accessed by the object's functions, allowing for encapsulation. The document then provides an overview of key C++ concepts like data types, tokens, operators, and input/output streams to introduce basic C++ syntax and programming.
45 Days C++ Programming Language Training in Ambalajatin batra
Are you looking for C++Programming Training In Ambala?
Now you search ends here... Batra Computer Centre provides you best C++ Programming Language Training in Ambala Cantt. We also proides you training in C, HTML, PHP, Web Designing, Web Development, SEO, SMO also.
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.
C++ is an object-oriented programming language that is considered intermediate-level as it includes both high-level and low-level features. It was initially called 'C with Classes' but was renamed to C++ in 1983. C++ was created in the early 1980s at Bell Labs by Bjarne Stroustrup and is based on the C language. C++ is called an object-oriented language because it views problems in terms of objects rather than procedures. Key concepts of object-oriented programming in C++ include classes, objects, data abstraction, encapsulation, polymorphism, and inheritance.
Learning C++ - Introduction to c++ programming 1Ali Aminian
This document provides an introduction to C++ programming, covering key concepts like the workspace, basics of the C++ environment, data types, and operations. It discusses setting up a Microsoft Visual Studio workspace and comments. The basics section explains preprocessor directives, header files, the main function framework, and input/output streams. Data types covered include integers, floating point, Boolean, characters, and enums. Operations explained are conditionals, loops like for and while, and logical/comparison operators. The document aims to familiarize readers with fundamental C++ concepts.
Keywords, identifiers ,datatypes in C++Ankur Pandey
Everything about Keywords, Identifiers,
Datatypes in C++, in this module you gain knowledge about what is Keywords, Identifiers,
Datatypes in C++ (Object oriented programming).
This document provides information about C++ programming language tokens and input/output operations. It defines various tokens like keywords, identifiers, literals, punctuators, and operators. It explains the basic structure of a C++ program and defines important headers like iostream. It also describes input/output streams like cout and cin, and input/output operators like << and >>.
The document discusses various C++ data types including built-in types like int and float, user-defined types like structures and classes, and derived types like arrays and pointers. It also covers constants, control structures for selection and loops, and the differences between constants, constant pointers, and pointers to constants.
This document provides an overview of C++ programming concepts including:
- Procedure-oriented programming focuses on tasks like reading, calculating and printing using functions, while object-oriented programming emphasizes data through objects and classes.
- C++ was developed to include object-oriented features while retaining C's simplicity, with classes, inheritance, and other features enabling abstract data types.
- Key concepts covered include classes, objects, member functions, inline functions, passing objects as parameters, returning objects, arrays of objects, and function overloading. Examples are provided to illustrate each concept.
This document discusses various C++ concepts including tokens, keywords, identifiers, constants, data types, user-defined data types like struct, union, enum, and class. It also covers derived data types like arrays, functions, and pointers. It provides examples and programs to demonstrate struct, union, enum, functions, pointers, and references. The document is a set of lecture notes that serves as an introduction to fundamental C++ programming concepts.
This document provides an introduction to C++ programming, covering key concepts like characters, tokens, keywords, identifiers, literals, operators, I/O streams, variables, comments, and common errors. It explains that Bjarne Stroustrup extended C to create C++, adding object-oriented features from Simula. The main components discussed are the building blocks of any C++ program - characters, tokens, data types, and basic input/output operations.
C Tokens, Escape sequence, Delimiters, Variables, Data types, Constants/ Literals, Expressions, Statements and Comments
https://github.com/ashim888/csit-c
This document summarizes Chapter 2 of a C++ basics textbook. Section 2.1 discusses variables and assignments, including declaring variables, assigning values, and keywords. Section 2.2 covers input and output streams like cout and cin. Section 2.3 reviews data types like int, double, char, and bool, and arithmetic expressions.
This document discusses different data types in C/C++ including character, integer, and real (float) data types. It explains that character data can be signed or unsigned and occupies 1 byte, integer data represents whole numbers using the int type, and float data represents decimal numbers. The document also covers numeric and non-numeric constants in C/C++ such as integer, octal, hexadecimal, floating point, character, and string constants.
This document provides an overview of C++ data types. It discusses fundamental data types like integer, character, float, and double. It also covers type modifiers, derived data types like arrays and functions, and other concepts like pointers, references, constants, classes, structures, unions, and enumerations. The document aims to explain the different data types and how they are used in C++.
The document discusses the history and key concepts of C++, including its creation by Bjarne Stroustrup, the influences on its development, and its combination of efficiency from C with ease of use from object-oriented programming. It explains the three main traits of object-oriented programming - encapsulation, polymorphism, and inheritance - and provides examples of each concept. The document also provides guidance for new C++ programmers on using header files, the main function, and input/output statements in their first C++ program.
The document discusses various C++ data types including built-in, derived, and user-defined data types. It describes the different built-in data types like int, char, float, double, void and their properties. It also discusses derived data types like arrays, functions, pointers, references, and constant. The document further explains user-defined data types like structures, unions and classes/objects in C++.
OOPs provides several benefits like reduced complexity, reusability of code, and less redundancy. It achieves this through concepts like encapsulation, inheritance and polymorphism. Some disadvantages are a steeper learning curve, larger program size and slower execution compared to procedural programming. OOPs can be applied in areas like databases, simulation, web applications and user interfaces. C++ is an object-oriented language that builds upon C with additional features like classes, function overloading and exception handling. It requires a C++ compiler to translate the code to an executable file.
This document describes a lab assignment on operators and expressions in C++. It includes theories on various operators like arithmetic, assignment, increment/decrement, relational, logical operators and precedence of operators. It then lists several activities for students to write programs demonstrating the use of these operators and expressions. These include calculating average, postfix/prefix increment, arithmetic operations on variables, modulus operator, and relational/logical operators. The document ends with exercises to write expressions and programs to calculate values based on given conditions.
OOPs concepts include objects, classes, encapsulation, inheritance, and polymorphism. Objects are run-time entities that can access class data through associated methods. Classes are user-defined data types that implement abstraction and encapsulation. Encapsulation provides an interface between an object's data and the program. Inheritance allows classes to inherit properties from superclasses and subclasses. Polymorphism allows an object to take different forms depending on its data type. Constructors initialize objects and destructors finalize them. OOPs benefits applications by building secure, modularized programs that are reusable and allow interference-free object coexistence.
This document discusses C++ input and output programming fundamentals. It covers topics like stream insertion and extraction operators, header files for input/output, escape sequences, and formatting output using manipulators. The lab activities practice getting user input, setting field widths, and left-justifying output. Exercises include displaying a pattern using manipulators, converting currency, and calculating the hypotenuse of a right triangle.
This document provides an overview of key object-oriented concepts including encapsulation, abstraction, inheritance, and polymorphism. Encapsulation involves grouping related data and procedures together and controlling access to an object's data. Abstraction focuses on common behaviors across objects rather than implementation details. Inheritance organizes similar objects in a hierarchy to consolidate common functionality. Polymorphism allows modifying inherited behaviors in descendant classes. The document uses examples of reactive substances like Mentos and Diet Coke to illustrate these concepts.
Introduction to object oriented languagefarhan amjad
This document discusses object-oriented programming (OOP) and its advantages over procedural programming. It defines some key OOP concepts like objects, classes, encapsulation, and inheritance. It explains that in OOP, programs are designed as collections of these discrete objects that combine data and behaviors. This reduces complexity and promotes reusability, flexibility, and maintainability. OOP also gives data more importance and provides mechanisms to hide data that procedural languages lack.
The document discusses object-oriented programming concepts including encapsulation, inheritance, polymorphism, and relationships. Encapsulation involves enclosing attributes and methods within a class. Inheritance allows code reuse by establishing subtypes that inherit characteristics from a parent class. Polymorphism can be achieved through method overloading and overriding. Relationships in object-oriented programming include inheritance for "is-a" relationships and aggregation/composition for "has-a" relationships.
Introduction - Imperative and Object-Oriented LanguagesGuido Wachsmuth
This document provides an overview of imperative and object-oriented languages. It discusses the properties of imperative languages like state, statements, control flow, procedures and types. It then covers object-oriented concepts like objects, messages, classes, inheritance and polymorphism. Examples are given in various languages like C, Java bytecode, x86 assembly to illustrate concepts like variables, expressions, functions and object-oriented features. Finally, it provides an outlook on upcoming lectures covering declarative language definition.
Cbse class 10 hindi course b model answers by candidates 2015Saurabh Singh Negi
The document discusses the benefits of exercise for mental health. Regular physical activity can help reduce anxiety and depression and improve mood and cognitive functioning. Exercise causes chemical changes in the brain that may help protect against mental illness and improve symptoms.
The document discusses object-oriented programming languages like C++, Smalltalk, and Java. It covers the basic concepts of object-oriented programming including objects, classes, encapsulation, inheritance, and polymorphism. Key points about each language are provided, such as C++ being an extension of C and introducing classes, Smalltalk being one of the earliest languages to support OOP, and Java combining elements of C++ and Smalltalk. Sample code in each language is also shown.
This document discusses the fundamentals of C++ programming including the structure of C++ programs, keywords, data types, variables, constants, and input/output statements. It provides the code for several sample programs and step-by-step instructions for writing, compiling, and running the programs to practice variable declaration, data types, and basic math operations. The document concludes with exercises to test understanding of concepts covered.
The document provides an overview of fundamental C# programming concepts including:
1) C# syntax is similar to C/C++ and Java with identifiers that can begin with letters or underscores but cannot be keywords. There are different capitalization styles for identifiers.
2) Types in C# include value types that contain data directly and reference types that contain a reference to an object.
3) Common programming tasks in C# include assigning values, making comparisons, selectively executing code blocks with if/else and switch statements, and iterating over data with for, do/while, while, and foreach loops.
4) Classes are blueprints for creating objects with fields to store data and methods to perform actions.
The document discusses object-oriented programming concepts and their implementation in creating a feedback form application. It introduces OOP concepts like inheritance, abstraction, encapsulation, and polymorphism. Inheritance allows classes to inherit and reuse attributes and behaviors from a parent class. Abstraction defines common properties of classes under a generalized superclass. Encapsulation hides internal details and data within classes. Polymorphism enables one interface to multiple forms of implementation through inheritance. The document provides examples of how these concepts can be applied to develop classes for different question types in a feedback form.
This document discusses various C programming concepts including keywords, identifiers, constants, operators, and special symbols. Key points:
- Keywords have fixed meanings and must be written in lowercase. Identifiers refer to user-defined variables, functions, and arrays and can include uppercase letters.
- Constants refer to fixed values and include integer, real, character, and string types. Integer constants can be decimal, octal, or hexadecimal.
- Operators include arithmetic, relational, logical, assignment, increment/decrement, conditional, bitwise, and special operators.
- Special symbols like [], (), {}, ;, *, and = have specific meanings in C programs. They are used for array indexing,
The document provides an overview of key concepts in C programming including comments, header files, character sets, tokens, keywords, constants, data types, and special symbols. It discusses various types of comments, the purpose of header files, the basic character set in C, different types of tokens, common keywords like auto, break, const, continue, and their usage. It also explains integer, character, string, and backslash constants as well as basic and special data types.
This document provides an overview of the C programming language development process. It discusses the different phases a C program goes through from editing the source code to execution. It describes the preprocessor, compiler, linker, and loader and their roles. It also covers C program structures like comments, header files, and the main function. Finally, it discusses some C fundamentals like data types, variables, literals, and variable scope.
This document provides an introduction and overview of the C programming language. It discusses the basic structure of a C program including preprocessor directives, global declarations, functions, and statements. It also covers fundamental C concepts such as variable declarations, data types, constants, comments, and input/output functions. The history and evolution of C from earlier languages like ALGOL and BCPL is presented.
This document provides an introduction and overview of the C programming language. It discusses the basic structure of a C program including preprocessor directives, global declarations, functions, and statements. It also covers fundamental C concepts such as variable declarations, data types, constants, comments, and input/output functions. The history and evolution of C from earlier languages like ALGOL and BCPL is presented.
This document provides an introduction and overview of the C programming language. It begins with a basic "Hello World" program and outlines the main components of a C program including preprocessor directives, functions, variables, data types, input/output, and comments. It also provides history on the development of C and describes the structure of C programs and key elements like functions, main functions, and comments.
A File is a collection of data stored in the secondary memory. So far data wa...bhargavi804095
A File is a collection of data stored in the secondary memory. So far data was entered into the programs through the keyboard. So Files are used for storing information that can be processed by the programs. Files are not only used for storing the data, programs are also stored in files. In order to use files, we have to learn file input and output operations. That is, how data is read and how to write into a file. A Stream is the important concept in C. The Stream is a common, logical interface to the various devices that comprise the computer. So a Stream is a logical interface to a file. There are two types of Streams, Text Stream and Binary Stream. A Text File can be thought of as a stream of characters that can be processed sequentially. It can only be processed in the forward direction.
The document discusses key concepts in C programming including:
1) The life cycle of a C program involving preprocessing, compilation, assembly, linking, and program execution in memory.
2) The structure of a C program including keywords, identifiers, variables, literals, and different variable types.
3) Details about integer, floating point, character, and string literals as well as escape sequences used in C programming.
Bsc cs i pic u-2 datatypes and variables in c languageRai University
The document discusses various topics related to C programming language including basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and conditional operators. It provides explanations and examples for each topic. The key points are that a C program contains functions organized into sections, all statements must end with a semicolon, comments are enclosed in /* */ , the main() function contains the main program logic, variables must be declared before use with a specified data type, and operators are used to manipulate variables and perform tasks like arithmetic, comparisons, assignments, and conditionals.
This document provides an overview of basic concepts in C programming including data types, variables, constants, and storage classes. It discusses the basic structure of a C program and sections like main(), functions, and declarations. It describes various data types in C like integer, float, character, and string. Rules for identifiers, keywords, and comments are also covered. The document explains variable declaration and assignment as well as constants like integer, real, character, string and escape sequences. Storage classes and scope of variables are discussed.
Btech i pic u-2 datatypes and variables in c languageRai University
This document discusses various topics related to C programming language including basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and input/output functions. It explains that a C program contains functions organized into sections like main, documentation, definitions, and subprograms. It provides rules for writing comments, declaring and initializing variables, and defining valid identifiers. It also describes different data types in C like integer, float, character, and string. Finally, it discusses various operators supported in C for arithmetic, relational, logical, assignment, increment/decrement operations.
Mca i pic u-2 datatypes and variables in c languageRai University
This document discusses various concepts related to data types and variables in the C programming language. It covers the basic structure of a C program and sections like documentation, definition, global declaration, main function, and subprogram sections. It describes rules for comments, the main method, declaration, data types like integer, floating point, character, and string. It also discusses variables, assigning values, and declaring variables with different storage classes.
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
The document discusses various topics related to C programming language such as basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and conditional operators. It explains that a C program consists of functions organized into sections like documentation, definitions, global declarations, main function, and subprograms. It provides rules for writing comments, declaring variables, and defining valid identifiers and constants. It also describes various data types in C including integer, floating point, character, and string types.
This document discusses variables in C++, including data types, identifiers, and variable declaration. It provides the following key points:
- Data types specify the type of data a variable can store (e.g. int, float, char) and determine how much memory is allocated. Common fundamental data types include integers, floating point numbers, booleans, characters, and strings.
- Identifiers are names given to variables and follow naming rules like starting with a letter and not being a reserved keyword. Variables must be declared before use by specifying the data type.
- Declaration syntax is the data type followed by the variable name(s). For example, "int x, y;" declares two integer variables.
This document summarizes key elements of a C program structure including comments, preprocessor directives, global declarations, the main function, and constants. Comments are used to explain the program and are enclosed in /* */. Preprocessor directives like #include add functionality. Global variables are declared outside functions and accessible to all. The main function is where program execution begins, enclosed in braces. Constants refer to fixed values defined using #define or const.
This document provides an introduction to the basic structure, syntax, data types, variables, constants, and input/output functions in the C programming language. It explains that a C program consists of pre-processor commands, functions, variables, statements, expressions, and comments. It also describes C's character set, tokens, keywords, identifiers, literals, strings, punctuators, operators, and fundamental and derived data types like integers, floats, characters, arrays, and structures. Finally, it discusses defining and initializing variables and constants, and using the printf() and scanf() functions for output and input.
This document provides an overview of C programming, including getting started, keywords, identifiers, variables, constants, and data types. It explains that C is an efficient programming language widely used for system and application software. It also covers the basics of compilers, keywords, variables, constants, and different data types like integers, floats, characters, and more. The document is intended for beginners to provide a solid foundation of C programming concepts.
This document discusses different types of constants in C programming including integer, floating point, character, and string literals. It provides examples of proper syntax for defining each constant type and explains that constants refer to fixed values that cannot be altered during program execution unlike regular variables. The document also reviews two methods for defining constants in C using the #define preprocessor or const keyword.
Variables, constants, I/O functions & Header Files document discusses:
1. Variables in C - Variables store data in memory locations and can change value. They are declared with a data type and name.
2. Constants in C - Constants cannot change value once declared. They include integer, floating point, character, and string literals.
3. Input/output functions in C - These allow programs to accept input and display output. Formatted functions like printf() and scanf() control formatting while unformatted functions like getch() and putch() do not.
4. Header files in C - Header files contain predefined library functions and are included using #include to access standard functions.
This document provides an overview of the physical and logical structures of an Oracle database. It discusses the datafiles, control files, redo log files, archive log files, and other physical structures that make up the database. It also explains the logical structures like tablespaces, data blocks, extents, segments, and schemas. The document outlines the functions of the System Global Area (SGA) and Program Global Area (PGA). It describes the various background processes like SMON, PMON, DBWR, LGWR, and others that manage the database instance. Finally, it covers backup methods for Oracle databases.
Indexes are optional database structures that improve the performance of queries on tables. Indexes work like the index in a book, allowing faster access to table data. The database automatically maintains indexes as the associated table data changes. Indexes can be created, dropped, or renamed as needed without affecting applications or other indexes.
Communication refers to the sharing of information or intelligence between individuals through a common system of symbols, signs, behaviors, or language. The main components of the communication process are the sender, message, channel, receiver, and response. Barriers to effective communication include improper encoding, bypassing, differences in frames of reference, physical and psychological distractions, and cultural differences. Methods of communication include verbal communication using speaking, non-verbal communication through body language and appearance, writing in various forms, and reading workplace documents. Techniques for improving communication skills are to increase self-confidence, practice speaking aloud, join online discussions, and share thoughts and feelings to build experience communicating.
The document discusses Linux file permissions including the sticky bit, SUID, and SGID permissions. It provides examples of how each permission works. The sticky bit prevents non-owners from deleting or renaming files within a directory. SUID runs scripts as the owner rather than the user running it. SGID runs scripts and sets group ownership for files based on the file/directory group owner.
This document discusses various Linux text processing and manipulation tools including grep, sed, awk, and uniq. It provides examples of using each tool to search for and extract information from log files and text data. Grep is used to search files for specific text patterns. Sed is used to substitute or delete text in files without opening them in an editor. Awk can extract specific fields from text and perform calculations. Uniq removes duplicate lines from files.
Linux is an open-source operating system created by Linus Torvalds in 1991. It evolved from the Linux kernel that Torvalds developed as a student. Linux uses a command line interface and shell, with popular shells including bash. The Linux file system organizes everything, including hardware devices, as files within a directory structure. Key directories include /bin for essential commands, /etc for configuration files, /boot for the kernel, /tmp for temporary files, /var for variable files, and /home for user files. In 1991, Torvalds' kernel combined with software from the GNU project to create a free operating system, addressing the goals of both.
The document outlines the key terms of a lease agreement between John Doe as the landlord and Jane Smith as the tenant. It specifies the monthly rent amount and due date, the security deposit required, allows for pets but with restrictions, and outlines the process for repairs, entry by the landlord, and early termination of the lease. The agreement is for a one year term beginning on January 1st, 2023 and ending December 31st, 2023.
The document appears to be a scanned collection of pages from a book or manual. It contains images of many pages with text and diagrams but no clear overall context or narrative to summarize. Individual pages discuss topics like electrical components, wiring diagrams, and technical specifications but there is no clear high-level topic or essence that can be determined from the random assortment of pages provided.
In procedural programs, logic follows procedures and instructions execute sequentially, while in object-oriented programs (OOP), the unit is the object which combines data and code. OOP programs encapsulate data within objects and assure security, while procedural programs expose data. Encapsulation binds code and data, inheritance allows acquiring properties of another object, and polymorphism allows a general interface for class actions. Initialization can only occur once while assignment can occur multiple times. OOP organizes programs around objects and well-defined interfaces to data, with objects controlling access to code.
A view is a stored representation of a SQL query that can be reused. Views allow restricting access to columns, reduce redundancy, and are read-only or updatable. Views must meet criteria like including primary keys for updating and are recompiled if their base tables change. Views are created with CREATE VIEW and modified with ALTER VIEW.
The document discusses the different types of SQL statements - DDL, DML, DCL, and TCL. It then provides details on data types supported by Oracle databases from version 9i to 11g including character, numeric, date/time, LOB, and rowid data types. The document concludes with sections on the CREATE TABLE statement and constraints that can be defined while creating a table.
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.pptHenry Hollis
The History of NZ 1870-1900.
Making of a Nation.
From the NZ Wars to Liberals,
Richard Seddon, George Grey,
Social Laboratory, New Zealand,
Confiscations, Kotahitanga, Kingitanga, Parliament, Suffrage, Repudiation, Economic Change, Agriculture, Gold Mining, Timber, Flax, Sheep, Dairying,
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
How Barcodes Can Be Leveraged Within Odoo 17Celine George
In this presentation, we will explore how barcodes can be leveraged within Odoo 17 to streamline our manufacturing processes. We will cover the configuration steps, how to utilize barcodes in different manufacturing scenarios, and the overall benefits of implementing this technology.
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...EduSkills OECD
Andreas Schleicher, Director of Education and Skills at the OECD presents at the launch of PISA 2022 Volume III - Creative Minds, Creative Schools on 18 June 2024.
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...TechSoup
Whether you're new to SEO or looking to refine your existing strategies, this webinar will provide you with actionable insights and practical tips to elevate your nonprofit's online presence.
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
1. 4210011 0010 1010 1101 0001 0100 1011
Basics of C++
1. Identifiers
2. Keywords
3. Fundamental data types
4. Declaration of variables
5. Scope of variables
6. Initialization of variables
7. Strings
8. Constants
9. Operators
10. Basic Input/Output
2. 421
0011 0010 1010 1101 0001 0100 1011
Identifiers
• Identifiers are name given to various program
elements.
• A valid identifier is a sequence of one or more
letters, digits or underscore characters.
• Neither spaces nor punctuation marks or
symbols can be part of an identifier.
• Only letters, digits and single underscore
characters are valid.
3. 421
0011 0010 1010 1101 0001 0100 1011
• Variable identifiers always have to begin with a
letter. They can also begin with an underline
character ( _ ), but in some cases these may be
reserved for compiler specific keywords or
external identifiers, as well as identifiers
containing two successive underscore characters
anywhere.
• They cannot match any keyword of the C++
language nor your compiler's specific ones,
which are reserved keywords.
5. 421
0011 0010 1010 1101 0001 0100 1011
• alternative representations for some
operators cannot be used as identifiers since
they are reserved words under some
circumstances:
– and, and_eq, bitand, bitor, compl, not, not_eq,
or, or_eq, xor, xor_eq
6. 421
0011 0010 1010 1101 0001 0100 1011
Fundamental data types
Name Description Size* Range*
char Character or small integer. 1byte
signed: -128 to 127
unsigned: 0 to 255
short
int (short)
Short Integer. 2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
long
int (long)
Long integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
bool
Boolean value. It can take one of
two values: true or false.
1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double
Double precision floating point
number.
8bytes
+/- 1.7e +/- 308 (~15
digits)
long double
Long double precision floating point
number.
8bytes
+/- 1.7e +/- 308 (~15
digits)
wchar_t Wide character. 2 or 4 bytes 1 wide character
7. 421
0011 0010 1010 1101 0001 0100 1011
Declaration of variables
// declaring and operating with variables
#include <iostream>
using namespace std;
int main () {
// declaring variables:
int a, b;
int result;
// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
std::cout << result;
// terminate the program:
return 0;
}
8. 421
0011 0010 1010 1101 0001 0100 1011
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 code at the
beginning of the body of the function main when we
declared that a, b, and result were of type int.
• A variable can be either of global or local scope. A
global variable is a variable declared in the main body of
the source code, outside all functions, while a local
variable is one declared within the body of a function or
a block.
10. 421
0011 0010 1010 1101 0001 0100 1011
• Global variables can be referred from anywhere
in the code, even inside functions, whenever it is
after its declaration.
• The scope of local variables is limited to the
block enclosed in braces ({}) where they are
declared. For example, if they are declared at the
beginning of the body of a function (like in
function main) their scope is between its
declaration point and the end of that function. In
the example above, this means that if another
function existed in addition to main, the local
variables declared in main could not be accessed
from the other function and vice versa.
11. 421
0011 0010 1010 1101 0001 0100 1011
Initialization of variables
• C-like initialization, is done by appending an equal sign
followed by the value to which the variable will be
initialized:
type identifier = initial_value ;
• The other way to initialize variables, known
as constructor initialization, is done by enclosing the
initial value between parentheses (()):
type identifier (initial_value) ;
12. 421
0011 0010 1010 1101 0001 0100 1011
// initialization of variables
#include <iostream>
using namespace std;
int main () {
int a=5; // initial value = 5
int b(2); // initial value = 2
int result; // initial value
undetermined
a = a + 3;
result = a - b;
std::cout << result;
return 0;
}
13. 421
0011 0010 1010 1101 0001 0100 1011
Strings
• Variables that can store non-numerical values that
are longer than one single character are known as
strings.
• The C++ language library provides support for
strings through the standard string class. This is
not a fundamental type, but it behaves in a similar
way as fundamental types do in its most basic
usage.
14. 421
0011 0010 1010 1101 0001 0100 1011
• A first difference with fundamental data types is that in
order to declare and use objects (variables) of this type we
need to include an additional header file in our source
code: <string> and have access to the std namespace
// my first string
#include <iostream>
#include <string>
using namespace std;
int main () {
string mystring = "This is a string";
cout << mystring;
return 0;
}
15. 421
0011 0010 1010 1101 0001 0100 1011
Constants
• Constants are expressions with a fixed value.
Literals
Literals are used to express particular values within the source code of a
program. We have already used these previously to give concrete
values to variables or to express messages we wanted our programs to
print out, for example, when we wrote:
a = 5;
the 5 in this piece of code was a literal constant.
Literal constants can be divided in Integer Numerals, Floating-Point
Numerals, Characters, Strings and Boolean Values.
16. 421
0011 0010 1010 1101 0001 0100 1011
1. Integer Numerals
They are numerical constants that identify integer decimal values.
• 1776
• 707
• -273
In addition to decimal numbers C++ allows the use as literal constants of
octal numbers (base 8) and hexadecimal numbers (base 16).
• 75 // decimal
• 0113 // octal
• 0x4b // hexadecimal
• 75u // unsigned int
• 75l // long
• 75ul // unsigned long
17. 421
0011 0010 1010 1101 0001 0100 1011
2. Floating Point Numbers
They express numbers with decimals and/or exponents. They
can include either a decimal point, an e character (that
expresses "by ten at the Xth height", where X is an integer
value that follows the e character), or both a decimal point
and an e character:
• 3.14159 // 3.14159
• 6.02e23 // 6.02 x 10^23
• 1.6e-19 // 1.6 x 10^-19
• 3.0 // 3.0
The default type for floating point literals is double. If you
explicitly want to express a float or long double numerical
literal, you can use the f or l suffixes respectively:
• 3.14159L // long double
• 6.02e23f // float
18. 421
0011 0010 1010 1101 0001 0100 1011
3. Character and string literals
There also exist non-numerical constants, like:
• 'z'
• 'p'
• "Hello world"
• "How do you do?"
The first two expressions represent single character constants, and the
following two represent string literals composed of several characters.
When writing both single character and string literals, it is necessary to
put the quotation marks surrounding them to distinguish them from
possible variable identifiers or reserved keywords. Notice the
difference between these two expressions:
• x
• 'x'
x alone would refer to a variable whose identifier is x, whereas 'x'
(enclosed within single quotation marks) would refer to the character
constant 'x'.
19. 421
0011 0010 1010 1101 0001 0100 1011
Character and string literals have certain peculiarities, like the escape codes. These are
special characters that are difficult or impossible to express otherwise in the source
code of a program, like newline (n) or tab (t). All of them are preceded by a
backslash (). Here you have a list of some of such escape codes:
• n newline
• r carriage return
• t tab
• v vertical tab
• b backspace
• f form feed (page feed)
• a alert (beep)
• ' single quote (')
• " double quote (")
• ? question mark (?)
• backslash ()
For example:
• 'n'
• 't'
• "Left t Right"
• "onentwonthree"
20. 421
0011 0010 1010 1101 0001 0100 1011
Additionally, you can express any character by its numerical ASCII code
by writing a backslash character () followed by the ASCII code
expressed as an octal (base-8) or hexadecimal (base-16) number. In
the first case (octal) the digits must immediately follow the backslash
(for example 23 or 40), in the second case (hexadecimal), an x
character must be written before the digits themselves (for example
x20 or x4A).
String literals can extend to more than a single line of code by putting a
backslash sign () at the end of each unfinished line.
• “string expressed in
two lines”
You can also concatenate several string constants separating them by one
or several blank spaces, tabulators, newline or any other valid blank
character:
• "this forms" "a single" "string" "of characters“
Finally, if we want the string literal to be explicitly made of wide
characters (wchar_t), instead of narrow characters (char), we can
precede the constant with the L prefix:
• L"This is a wide character string"
Wide characters are used mainly to represent non-English or exotic
character sets.
21. 421
0011 0010 1010 1101 0001 0100 1011
4. Boolean literals
There are only two valid Boolean values: true
and false. These can be expressed in C++ as
values of type bool by using the Boolean
literals true and false.
22. 421
0011 0010 1010 1101 0001 0100 1011
5. Defined constants (#define)
You can define your own names for constants
that you use very often without having to
resort to memory-consuming variables,
simply by using the #define preprocessor
directive. Its format is:
#define identifier value
• #define PI 3.14159
• #define NEWLINE 'n'
23. 421
0011 0010 1010 1101 0001 0100 1011
// defined constants: calculate circumference
#include <iostream>
using namespace std;
#define PI 3.14159
#define NEWLINE 'n'
int main () {
double r=5.0; // radius
double circle;
circle = 2 * PI * r;
cout << circle;
cout << NEWLINE;
return 0;
}
24. 421
0011 0010 1010 1101 0001 0100 1011
• In fact the only thing that the compiler preprocessor
does when it encounters #define directives is to
literally replace any occurrence of their identifier (in
the previous example, these were PI and NEWLINE)
by the code to which they have been defined
(3.14159 and 'n' respectively).
• The #define directive is not a C++ statement but a
directive for the preprocessor; therefore it assumes
the entire line as the directive and does not require a
semicolon (;) at its end. If you append a semicolon
character (;) at the end, it will also be appended in
all occurrences of the identifier within the body of
the program that the preprocessor replaces.
25. 421
0011 0010 1010 1101 0001 0100 1011
6. Declared constants (const)
With the const prefix you can declare constants with
a specific type in the same way as you would do
with a variable:
const int pathwidth = 100;
const char tabulator = 't';
Here, pathwidth and tabulator are two typed
constants. They are treated just like regular
variables except that their values cannot be
modified after their definition.
26. 421
0011 0010 1010 1101 0001 0100 1011
Operators
Operators are used to operate on operands to
produce some result.
27. 421
0011 0010 1010 1101 0001 0100 1011
Assignment (=)
The assignment operator assigns a value to a variable.
a = 5;
This statement assigns the integer value 5 to the variable a.
The part at the left of the assignment operator (=) is known
as the lvalue (left value) and the right one as the rvalue
(right value). The lvalue has to be a variable whereas the
rvalue can be either a constant, a variable, the result of an
operation or any combination of these.
The most important rule when assigning is the right-to-left
rule: The assignment operation always takes place from
right to left, and never the other way:
a = b;
This statement assigns to variable a (the lvalue) the value
contained in variable b (the rvalue). The value that was
stored until this moment in a is not considered at all in this
operation, and in fact that value is lost.
28. 421
0011 0010 1010 1101 0001 0100 1011
// assignment operator
#include <iostream>
using namespace std;
int main () {
int a, b; // a:?, b:?
a = 10; // a:10, b:?
b = 4; // a:10, b:4
a = b; // a:4, b:4
b = 7; // a:4, b:7
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
29. 421
0011 0010 1010 1101 0001 0100 1011
A property that C++ has over other programming languages is
that the assignment operation can be used as the rvalue (or
part of an rvalue) for another assignment operation. For
example:
a = 2 + (b = 5);
is equivalent to:
b = 5;
a = 2 + b;
that means: first assign 5 to variable b and then assign to a the
value 2 plus the result of the previous assignment of b (i.e.
5), leaving a with a final value of 7.
The following expression is also valid in C++:
a = b = c = 5;
It assigns 5 to the all three variables: a, b and c.
30. 421
0011 0010 1010 1101 0001 0100 1011
Arithmetic operators ( +, -, *, /, % )
The five arithmetical operations supported by the C++ language are:
+ addition
- subtraction
* multiplication
/ division
% modulo
Operations of addition, subtraction, multiplication and division literally
correspond with their respective mathematical operators. The only
one that you might not be so used to see is modulo; whose operator is
the percentage sign (%). Modulo is the operation that gives the
remainder of a division of two values. For example, if we write:
a = 11 % 3;
the variable a will contain the value 2, since 2 is the remainder from
dividing 11 between 3.
31. 421
0011 0010 1010 1101 0001 0100 1011
Compound assignment (+=, -=, *=, /=, %=, >>=,
<<=, &=, ^=, |=)
When we want to modify the value of a variable by
performing an operation on the value currently stored in that
variable we can use compound assignment operators:
expression is equivalent to
value += increase; value = value + increase;
a -= 5; a = a - 5;
a /= b; a = a / b;
price *= units + 1; price = price * (units + 1);
32. 421
0011 0010 1010 1101 0001 0100 1011
// compound assignment operators
#include <iostream>
using namespace std;
int main () {
int a, b=3;
a = b;
a+=2; // equivalent to a=a+2
cout << a;
return 0;
}
33. 421
0011 0010 1010 1101 0001 0100 1011
Increase and decrease (++, --)
Shortening even more some expressions, the increase
operator (++) and the decrease operator (--) increase
or reduce by one the value stored in a variable. They
are equivalent to +=1 and to -=1, respectively. Thus:
c++;
c+=1;
c=c+1;
are all equivalent in its functionality: the three of them
increase by one the value of c.
34. 421
0011 0010 1010 1101 0001 0100 1011
A characteristic of this operator is that it can be used both as a prefix and
as a suffix. That means that it can be written either before the variable
identifier (++a) or after it (a++). Although in simple expressions like
a++ or ++a both have exactly the same meaning, in other expressions
in which the result of the increase or decrease operation is evaluated
as a value in an outer expression they may have an important
difference in their meaning: In the case that the increase operator is
used as a prefix (++a) the value is increased before the result of the
expression is evaluated and therefore the increased value is
considered in the outer expression; in case that it is used as a suffix
(a++) the value stored in a is increased after being evaluated and
therefore the value stored before the increase operation is evaluated
in the outer expression. Notice the difference:
Example 1 Example 2
B=3;
A=++B;
// A contains 4, B contains 4
B=3;
A=B++;
// A contains 3, B contains 4
In Example 1, B is increased before its value is copied to A. While in
Example 2, the value of B is copied to A and then B is increased.
35. 421
0011 0010 1010 1101 0001 0100 1011
Relational and equality operators ( ==, !=, >, <, >=,
<= )
In order to evaluate a comparison between two
expressions we can use the relational and equality
operators. The result of a relational operation is a
Boolean value that can only be true or false,
according to its Boolean result.
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
36. 421
0011 0010 1010 1101 0001 0100 1011
a=2, b=3 and c=6
(a == 5) // evaluates to false since a is not equal to 5.
(a*b >= c) // evaluates to true since (2*3 >= 6) is
true.
(b+4 > a*c) // evaluates to false since (3+4 > 2*6) is
false.
((b=2) == a) // evaluates to true.
37. 421
0011 0010 1010 1101 0001 0100 1011
Logical operators ( !, &&, || )
The Operator ! is the C++ operator to perform the
Boolean operation NOT, it has only one operand,
located at its right, and the only thing that it does is
to inverse the value of it, producing false if its
operand is true and true if its operand is false.
Basically, it returns the opposite Boolean value of
evaluating its operand. For example:
• !(5 == 5) // evaluates to false because the
expression at its right (5 == 5) is true.
• !(6 <= 4) // evaluates to true because (6 <= 4)
would be false.
• !true // evaluates to false
• !false // evaluates to true.
38. 421
0011 0010 1010 1101 0001 0100 1011
The logical operators && and || are used when evaluating
two expressions to obtain a single relational result. The
operator && corresponds with Boolean logical operation
AND. This operation results true if both its two operands
are true, and false otherwise. The following panel shows
the result of operator && evaluating the expression a
&& b:
&& OPERATOR
a b a && b
true true true
true false false
false true false
false false false
39. 421
0011 0010 1010 1101 0001 0100 1011
The operator || corresponds with Boolean logical
operation OR. This operation results true if either
one of its two operands is true, thus being false
only when both operands are false themselves.
Here are the possible results of a || b:
|| OPERATOR
a b a || b
true true true
true false true
false true true
false false false
41. 421
0011 0010 1010 1101 0001 0100 1011
When using the logical operators, C++ only evaluates what is
necessary from left to right to come up with the combined
relational result, ignoring the rest. Therefore, in this last
example ((5==5)||(3>6)), C++ would evaluate first whether
5==5 is true, and if so, it would never check whether 3>6 is
true or not. This is known as short-circuit evaluation, and
works like this for these operators:
operator short-circuit
&&
if the left-hand side expression is false, the combined result is false (right-hand side
expression not evaluated).
||
if the left-hand side expression is true, the combined result is true (right-hand side
expression not evaluated).
42. 421
0011 0010 1010 1101 0001 0100 1011
This is mostly important when the right-hand
expression has side effects, such as altering
values:
if ((i<10)&&(++i<n)) { /*...*/ }
This combined conditional expression increases
i by one, but only if the condition on the left of
&& is true, since otherwise the right-hand
expression (++i<n) is never evaluated.
43. 421
0011 0010 1010 1101 0001 0100 1011
Conditional operator ( ? )
The conditional operator evaluates an expression returning a
value if that expression is true and a different one if the
expression is evaluated as false. Its format is:
condition ? result1 : result2
If condition is true the expression will return result1, if it is
not it will return result2.
• 7==5 ? 4 : 3 // returns 3, since 7 is not equal to 5.
• 7==5+2 ? 4 : 3 // returns 4, since 7 is equal to 5+2.
• 5>3 ? a : b // returns the value of a, since 5 is greater
than 3.
• a>b ? a : b // returns whichever is greater, a or b.
44. 421
0011 0010 1010 1101 0001 0100 1011
Comma operator ( , )
The comma operator (,) is used to separate two or
more expressions that are included where only one
expression is expected. When the set of expressions
has to be evaluated for a value, only the rightmost
expression is considered.
For example, the following code:
a = (b=3, b+2);
Would first assign the value 3 to b, and then assign
b+2 to variable a. So, at the end, variable a would
contain the value 5 while variable b would contain
value 3.
45. 421
0011 0010 1010 1101 0001 0100 1011
Bitwise Operators ( &, |, ^, ~, <<, >> )
Bitwise operators modify variables considering the bit patterns
that represent the values they store.
operator asm equivalent description
& AND Bitwise AND
| OR Bitwise Inclusive OR
^ XOR Bitwise Exclusive OR
~ NOT Unary complement (bit inversion)
<< SHL Shift Left
>> SHR Shift Right
46. 421
0011 0010 1010 1101 0001 0100 1011
Explicit type casting operator
Type casting operators allow you to convert a datum of a
given type to another. There are several ways to do this in
C++. The simplest one, which has been inherited from the C
language, is to precede the expression to be converted by
the new type enclosed between parentheses (()):
int i;
float f = 3.14;
i = (int) f;
The previous code converts the float number 3.14 to an integer
value (3), the remainder is lost. Here, the typecasting
operator was (int). Another way to do the same thing in C++
is using the functional notation: preceding the expression to
be converted by the type and enclosing the expression
between parentheses:
i = int ( f );
Both ways of type casting are valid in C++.
47. 421
0011 0010 1010 1101 0001 0100 1011
sizeof()
This operator accepts one parameter, which can be
either a type or a variable itself and returns the
size in bytes of that type or object:
a = sizeof (char);
This will assign the value 1 to a because char is a
one-byte long type.
The value returned by sizeof is a constant, so it is
always determined before program execution.
48. 421
0011 0010 1010 1101 0001 0100 1011
Precedence of operators
When writing complex expressions with
several operands, we may have some doubts
about which operand is evaluated first and
which later. For example, in this
expression:
a = 5 + (7 % 2) // with a result of 6, or
a = (5 + 7) % 2 // with a result of 0
50. 421
0011 0010 1010 1101 0001 0100 1011
Basic Input/Output
• Using the standard input and output library, we will be able
to interact with the user by printing messages on the screen
and getting the user's input from the keyboard.
• C++ uses a convenient abstraction called streams to perform
input and output operations in sequential media such as the
screen or the keyboard. A stream is an object where a
program can either insert or extract characters to/from it.
We do not really need to care about many specifications
about the physical media associated with the stream - we
only need to know it will accept or provide characters
sequentially.
• The standard C++ library includes the header file iostream,
where the standard input and output stream objects are
declared.
51. 421
0011 0010 1010 1101 0001 0100 1011
• Standard Output (cout)
• By default, the standard output of a program is the
screen, and the C++ stream object defined to access
it is cout.
cout is used in conjunction with the insertion
operator, which is written as << (two "less than"
signs).
cout << “Hello"; // prints Hello on screen
cout << 120; // prints number 120 on screen
cout << x; // prints the content of x on screen
52. 421
0011 0010 1010 1101 0001 0100 1011
• Standard Input (cin)
• The standard input device is usually the keyboard.
Handling the standard input in C++ is done by
applying the overloaded operator of extraction (>>)
on the cin stream. The operator must be followed by
the variable that will store the data that is going to
be extracted from the stream. For example:
int age;
cin >> age;
53. 421
0011 0010 1010 1101 0001 0100 1011
• cin and strings
• We can use cin to get strings with the extraction
operator (>>) as we do with fundamental data type
variables:
cin >> mystring;
• cin extraction stops reading as soon as if finds any
blank space character. The solution to get sentence
is: we can use the function getline.
54. 421
0011 0010 1010 1101 0001 0100 1011
// cin with strings
#include <iostream>
#include <string>
using namespace std;
int main () {
string mystr;
cout << "What's your name? ";
getline (cin, mystr);
cout << "Hello " << mystr << ".n";
cout << "What is your favorite team? "; getline (cin,
mystr);
cout << "I like " << mystr << " too!n"; return 0;
}
55. 421
0011 0010 1010 1101 0001 0100 1011
• stringstream
• The standard header file <sstream> defines a class
called stringstream that allows a string-based object
to be treated as a stream. This way we can perform
extraction or insertion operations from/to strings,
which is especially useful to convert strings to
numerical values and vice versa. For example, if we
want to extract an integer from a string we can
write:
string mystr ("1204");
int myint;
stringstream(mystr) >> myint;
* The values of the columns Size and Range depend on the system the program is compiled for. The values shown above are those found on most 32-bit systems. But for other systems, the general specification is that int has the natural size suggested by the system architecture (one "word" ) and the four integer types char, short, int and long must each one be at least as large as the one preceding it, with char being always one byte in size. The same applies to the floating point types float, double and long double, where each one must provide at least as much precision as the preceding one.
This declares a string object with a value of "1204", and an int object. Then we use stringstream's constructor to construct an object of this type from the string object. Because we can use stringstream objects as if they were streams, we can extract an integer from it as we would have done on cin by applying the extractor operator (>>) on it followed by a variable of type int. After this piece of code, the variable myint will contain the numerical value 1204.
In this example, we acquire numeric values from the standard input indirectly. Instead of extracting numeric values directly from the standard input, we get lines from the standard input (cin) into a string object (mystr), and then we extract the integer values from this string into a variable of type int (quantity). Using this method, instead of direct extractions of integer values, we have more control over what happens with the input of numeric values from the user, since we are separating the process of obtaining input from the user (we now simply ask for lines) with the interpretation of that input. Therefore, this method is usually preferred to get numerical values from the user in all programs that are intensive in user input.