1) The document provides an overview of C++ basics including variables, data types, input/output, arithmetic operators, and comments. It discusses variable naming, declarations, initialization, and assignment.
2) Key data types discussed include integers, floating-point numbers, characters, Booleans, and strings. The string class allows strings to be manipulated similarly to other data types.
3) Input is handled with cin and output with cout. Escape sequences can be used to control formatting. Arithmetic operators allow expressions to be formed. Comments start with // and /* */.
This document discusses C++ comments, including single-line and multi-line comments. Single-line comments begin with // and multi-line comments begin with /* and end with */. It also covers basic data types in C++ like int, char, float, and double, as well as variables, constants, user input, operators, and identifiers.
- Bjarne Stroustrup is credited as the creator of C++.
- There are different types of tokens in C++ including keywords, identifiers, variables, constants, punctuators, and operators.
- Key concepts discussed include variables, constants, data types, expressions, input/output, control statements like if/else and loops.
- The document provides an overview of many fundamental C++ concepts in a structured manner.
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.
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 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++.
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.
C programming language:- Introduction to C Programming - Overview and Importa...SebastianFrancis13
油
C, a foundational programming language, emerged in the early 1970s by Dennis Ritchie at Bell Labs. While not the most beginner-friendly language due to its proximity to the underlying hardware, C's power lies in its ability to directly manipulate memory and interact with computer systems at a low level. This fine-grained control allows programmers to create efficient, high-performance software.
C's core elements include variables for data storage, operators for performing calculations and comparisons, control flow statements for directing program execution, and functions for modularizing code. It offers a rich set of data types, like integers, floating-point numbers, and characters, to represent diverse information. C's strength lies in its ability to manage memory allocation explicitly, allowing programmers to optimize memory usage for performance-critical applications. This granular control, however, comes with the responsibility of preventing memory leaks and other errors that can cause program crashes.
C's influence on the programming world is undeniable. It serves as the foundation for countless languages like C++, Java, and Python, which borrow heavily from its syntax and core concepts. Operating systems like Linux and macOS are written primarily in C, highlighting its ability to create robust and efficient system software. Even high-level applications often rely on C libraries for performance-sensitive tasks like graphics rendering or device drivers. In essence, C remains a cornerstone of modern computing, even as newer languages emerge, due to its unique blend of efficiency, control, and historical significance.
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.
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,
C was developed by Dennis Ritchie at Bell Labs in 1972. It is a structured, portable, middle-level programming language that uses a top-down approach. A C program consists of functions, with one function named main serving as the starting point. C programs can include comments, preprocessor directives, variables, constants, data types and expressions connected with operators.
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
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.
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.
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.
Asit Bangalore is providing best Programming course "C LANGUAGE" and helped them to take internship program which is helped to get real time exposure and placements in global world. For more details Please visit our website.
Distillation is a widely used method for separating mixtures油based on differences in the conditions required to change the油phase of components of the mixture.
To separate a mixture of liquids, the liquid can be heated to force components, which have different boiling points, into the gas phase. The gas is then condensed back into liquid form and collected.
Distillation can be considered as a physical separation process not a chemical reaction.
Distillation involves selective evaporation and subsequent condensation of a component in a liquid mixture.
It is a separation technique that can be used to either increase the concentration of a particular component in the mixture or to obtain (almost) pure components from the mixture.
Under a given pressure, the temperature at which a pure liquid distills (or boils) is known as Boiling Point .
Technically, the boiling point of a liquid is the temperature at which the vapor pressure of a liquid equals to the surrounding atmospheric pressure, allowing bubbles of vapor to form and rise through the liquid.油
Distillation allows one of the liquid mixture's components into a gaseous state, taking advantage of the difference in their boiling points.
More Related Content
Similar to THE C++ LECTURE 2 ON DATA STRUCTURES OF C++ (20)
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 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++.
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.
C programming language:- Introduction to C Programming - Overview and Importa...SebastianFrancis13
油
C, a foundational programming language, emerged in the early 1970s by Dennis Ritchie at Bell Labs. While not the most beginner-friendly language due to its proximity to the underlying hardware, C's power lies in its ability to directly manipulate memory and interact with computer systems at a low level. This fine-grained control allows programmers to create efficient, high-performance software.
C's core elements include variables for data storage, operators for performing calculations and comparisons, control flow statements for directing program execution, and functions for modularizing code. It offers a rich set of data types, like integers, floating-point numbers, and characters, to represent diverse information. C's strength lies in its ability to manage memory allocation explicitly, allowing programmers to optimize memory usage for performance-critical applications. This granular control, however, comes with the responsibility of preventing memory leaks and other errors that can cause program crashes.
C's influence on the programming world is undeniable. It serves as the foundation for countless languages like C++, Java, and Python, which borrow heavily from its syntax and core concepts. Operating systems like Linux and macOS are written primarily in C, highlighting its ability to create robust and efficient system software. Even high-level applications often rely on C libraries for performance-sensitive tasks like graphics rendering or device drivers. In essence, C remains a cornerstone of modern computing, even as newer languages emerge, due to its unique blend of efficiency, control, and historical significance.
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.
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,
C was developed by Dennis Ritchie at Bell Labs in 1972. It is a structured, portable, middle-level programming language that uses a top-down approach. A C program consists of functions, with one function named main serving as the starting point. C programs can include comments, preprocessor directives, variables, constants, data types and expressions connected with operators.
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
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.
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.
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.
Asit Bangalore is providing best Programming course "C LANGUAGE" and helped them to take internship program which is helped to get real time exposure and placements in global world. For more details Please visit our website.
Distillation is a widely used method for separating mixtures油based on differences in the conditions required to change the油phase of components of the mixture.
To separate a mixture of liquids, the liquid can be heated to force components, which have different boiling points, into the gas phase. The gas is then condensed back into liquid form and collected.
Distillation can be considered as a physical separation process not a chemical reaction.
Distillation involves selective evaporation and subsequent condensation of a component in a liquid mixture.
It is a separation technique that can be used to either increase the concentration of a particular component in the mixture or to obtain (almost) pure components from the mixture.
Under a given pressure, the temperature at which a pure liquid distills (or boils) is known as Boiling Point .
Technically, the boiling point of a liquid is the temperature at which the vapor pressure of a liquid equals to the surrounding atmospheric pressure, allowing bubbles of vapor to form and rise through the liquid.油
Distillation allows one of the liquid mixture's components into a gaseous state, taking advantage of the difference in their boiling points.
Explainability and Transparency in Artificial Intelligence: Ethical Imperativ...AI Publications
油
Artificial Intelligence (AI) is increasingly embedded in high-stakes domains such as healthcare, finance, and law enforcement, where opaque decision-making raises significant ethical concerns. Among the core challenges in AI ethics are explainability and transparencykey to fostering trust, accountability, and fairness in algorithmic systems. This review explores the ethical foundations of explainable AI (XAI), surveys leading technical approaches such as model-agnostic interpretability techniques and post-hoc explanation methods and examines their inherent limitations and trade-offs. A real-world case study from the healthcare sector highlights the critical consequences of deploying non-transparent AI models in clinical decision-making. The article also discusses emerging regulatory frameworks and underscores the need for interdisciplinary collaboration to address the evolving ethical landscape. The review concludes with recommendations for aligning technical innovation with ethical imperatives through responsible design and governance.
Production Planning & Control and Inventory Management.pptxVirajPasare
油
Production Planning and Control : Importance, Objectives and Functions . Inventory Management - Meaning, Types , Objectives, Selective Inventory Control : ABC Analysis
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...yadavchandan322
油
All the materials and content contained in Project report is for educational purpose and reflect the views of the industry which are drawn from various research on pasta machine. PM FME- Detailed Project Report of Multigrain Pasta Making Unit. 3. 1. PROJECT ... A pasta extruder is a machine that makes pasta dough through dies to.The process is quite simple and requires not much skilled labour. The machine itself is high technology and provides the manufacturers to produce noodles with. In this article, you will be able to get all the detail about a pasta-making business unit in India and the financial status of this business as well.ENGINEERS INDIA RESEARCH INSTITUTE - Service Provider of Project Report on PASTA PRODUCTION PLANT (SHORT PASTA) [CODE NO. 1632] based in Delhi, India.
Macaroni Machines are used to produce pasta from the raw material. With ... The views expressed in this Project Report are advisory in nature. SAMADHAN.
Industry 4.0: Transforming Modern Manufacturing and BeyondGtxDriver
油
This document explores the fundamental concepts, technologies, and applications of Industry 4.0. Topics include automation, IoT (Internet of Things), smart factories, cyber-physical systems, and the integration of AI and big data analytics in industrial processes. It serves as a comprehensive resource for students, professionals, and enthusiasts eager to delve into the fourth industrial revolution.
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...NIT SILCHAR
油
Self-Compacting Concrete (SCC) is a high-performance material that flows under its own weight, eliminating the need for vibration. It offers superior workability, durability, and structural efficiency, making it ideal for complex designs, congested reinforcement, and sustainable construction practices.
2. Outline
Layout of
simple ++
program
Variables Identifiers
Assignment
statements
Uninitialized
variables
Output
using cout
Input using
cin
Escape
sequences
Data types Integers
Floating
point
Type char
Class string Type bool
Arithmetic
operators and
expressions
Comments
Naming
constants
4. Sample Program
// This is a simple C++ program.
#include <iostream>
using namespace std;
int main()
{
cout<<Welcome to Computer Programming
course;
return 0;
}
5. 遺或鰻意禽
#include<iostream>
A program includes various programming elements
that are already defined in the standard C++ library.
In order to use such pre-defined elements in a
program, an appropriate header/directives must be
included in the program.
Directives always begin with the symbol #.
<iostream> is the name of a library that contains the
definitions of the routines that handle input from the
keyboard and output to the screen.
Do not include extra space between the < and the
iostream file name or between the end of the file
name and the closing >.
6. using namespace std;
This line says that the names defined in
iostream are to be interpreted in the
standard way.
int main()
It tells that your main part of a program
starts here.
{ }
Braces mark beginning and end of the
main function.
return 0;
The last line in the program. It marks
end of the program.
7. Variables
Variable is the basic storage unit in a program. It is
a name given to a memory location.
The compiler assigns a memory location to each
variable name in the program. The value of the
variable, in a coded form, is kept in the memory
location assigned to that variable.
We do not know what addresses the compiler will
choose for the variables in our program.
Data held in a variable is called its value or a literal;
Number/data held by a C++ variable can be
changed.
A C++ variable is guaranteed to have some value in
it, if only a garbage number left in the computers
memory by some previously run program.
8. Names: Identifiers
Identifiers are used as names for variables and
other items in a C++ program.
To make your program easy to understand, you
should always use meaningful names for variables.
Rules for naming variables:
You cannot use a C++ keyword (reserved word)
as a variable name.
Variable names in C++ can range from 1 to 255
characters.
All variable names must begin with a letter of
the alphabet (a-z, A-Z) or an underscore( _ ).
9. 遺或鰻意禽
After the first initial letter, variable names
can also contain letters and numbers.
No spaces or special characters allowed.
C++ is case Sensitive. Uppercase characters
are distinct from lowercase characters.
Examples:
A, a_1, x123 (legal)
1ab, da%, 1-2, (not acceptable)
Test, test, TEST (case-sensitive)
10. Variable declarations
Every variable in a C++ program must be declared
before the variable can be used.
When you declare a variable, you are telling the
compilerand, ultimately, the computerwhat
kind of data you will be storing in the variable, and
what size of memory location to use for the
variable.
Each declaration ends with a semicolon (;).
When there is more than one variable in a
declaration, the variables are separated by
commas.
The kind of data that is held in a variable is called
its type and the name for the type, such as int or
double, is called a type name.
11. Syntax
The syntax for a programming languages is the set
of grammar rules for that language.
The syntax for variable declarations is as follows:
Syntax
Type_Name Var_Name_1, Var_Name_2, ...;
Examples
int count, sum, number_of_person;
double distance;
12. Assignment statements
In an assignment statement, first the expression
on the right-hand side of the equal sign is
evaluated, and then the variable on the left-hand
side of the equal sign is set equal to this value.
In an assignment statement, the expression on
the right-hand side of the equal sign can simply
be another variable or a constant.
Syntax
Variable = Expression;
Examples
sum=a; //variable
distance = rate * time; //expression
count=12; //constant
13. Uninitialized variables
Variable that has not been given a value is
said to be uninitialized.
One way to avoid an uninitialized variable
is to initialize variables at the same time
they are declared.
You can initialize some, all, or none of the
variables in a declaration that lists more
than one variable.
Examples:
int count=0; double avg=99.9; int a=10, b,
c=0;
15. Output using cout
The values of variables as well as strings of text
may be output to the screen using cout.
The arrow notation << is often called the insertion
operator.
You can simply list all the items to be output
preceding each item to be output with the arrow
symbols <<.
Strings must be included in double quotes.
Examples:
cout<<This is our first c++ program;
cout<<The sum is<<sum;
cout<<distance is<<(time * speed);
16. Input using cin
A cin statement sets variables equal to values
typed in at the keyboard.
cin is a predefined variable that reads data from
the keyboard with the extraction operator (>>).
Syntax
cin >> Variable_1 >> Variable_2 >> ... ;
Example
cin >> number >> size;
cin >> time;
17. Escape sequences
The backslash, , preceding a character
tells the compiler that the character
following the does not have the same
meaning as the character appearing by
itself.
Such a sequence is called an escape
sequence.
18. 遺或鰻意禽
Name Escape
sequence
Description
New line n Cursor moves to next line
Horizontal tab t Cursor moves to next tab stop
Beep a Computer generates a beep
Backslash Backslash is printed
Single quote Single quotation mark is printed
Double quote Double quotation mark is printed
Return r Cursor moves to beginning of
current line
Backspace b Cursor moves one position left
19. Data Types
Data types are used to tell the variables the type
of data it can store.
Whenever a variable is defined in C++, the
compiler allocates some memory for that variable
based on the data-type with which it is declared.
Every data type requires a different amount of
memory.
20. Integer types
The integer data type basically represents whole
numbers (no fractional parts).
The reason is threefold.
First, some things in the real world are not
fractional.
Second, the integer data type is often used to
control program flow by counting.
Third, integer processing is significantly faster
within the CPU than is floating point processing.
22. Floating point types
The floating-point family of data types represents
number values with fractional parts.
They are technically stored as two integer values:
a mantissa and an exponent.
They are always signed.
A floating_point number can also be a scientific
number with an "e" to indicate the power of 10:
23. Type char
Values of the type char are single symbols such
as a letter, digit, or punctuation mark.
A variable of type char can hold any single
character on the keyboard e.g., A' or '+' or an
'a.
Note that uppercase and lowercase versions of
a letter are considered different characters.
The text in double quotes that are output using
cout are called string values.
Be sure to notice that string constants are
placed inside of double quotes, while constants
of type char are placed inside of single quotes.
24. Class string
string class is used to process strings in a manner
similar to the other data types.
To use the string class we must first include the
string library:
#include <string>
You declare variables of type string just as you
declare variables of types int or double.
string day;
day = "Monday";
25. 遺或鰻意禽
You may use cin and cout to read data into
strings.
You can use + operator between two strings to
concatenate them.
When you use cin to read input into a string
variable, the computer only reads until it
encounters a whitespace character. Whitespace
characters are all the characters that are
displayed as blank spaces on the screen, including
the blank or space character, the tab character,
and the new-line character 'n. This means that
so far you cannot input a string that contains
spaces.
26. Type bool
Expressions of type bool are called Boolean
after the English mathematician George Boole,
who formulated rules for mathematical logic.
Boolean expressions evaluate to one of the two
values, true or false.
Boolean expressions are used in branching and
looping statements.
27. Example
#include <iostream>
using namespace std;
int main() {
bool isCodingFun = true;
int i=100;
float f=23.6;
char ch=h;
double d = 12E4;
string s=Hello;
cout << isCodingFun << endl;
cout << value of int=<<i<<endl;
28. 遺或鰻意禽
cout << value of float=<<f<<endl;
cout << value of double=<<d<<endl;
cout << value of char=<<ch<<endl;
cout << value of string=<<s<<endl;
cout<<ASCII value of
char=<<int(ch)<<endl;
cout<<Integer to char=<<char(i)<<endl;
return 0;
}
29. 遺或鰻意禽
OUTPUT:
1
value of int=100
value of float=23.6
value of ouble=1.2e+013
value of char=h
value of string=hello
ASCII value of char=104
Integer to char=d
30. sizeof() Function
The sizeof is a keyword, it is a compile-time
operator that determines the size, in bytes, of a
variable or data type.
The sizeof operator can be used to get the size
primitive as well as user defined data types.
The syntax of using sizeof is as follows:
sizeof (data type)
31. Example
#include <iostream>
using namespace std;
int main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of long long: " << sizeof(long long) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
return 0;
}
32. Arithmetic operators and expressions
In a C++ program, you can combine variables
and/or numbers using the arithmetic operators +
for addition, for subtraction, * for multiplication,
and / for division.
The % operation gives the remainder.
The computer will follow rules called precedence
rules that determine the order in which the
operators, such as + and *, are performed. These
precedence rules are similar to rules used in algebra
and other mathematics classes.
35. Comment
In C++ the symbols // are used to indicate the start
of a comment.
All of the text between the // and the end of the
line is a comment.
The compiler simply ignores anything that follows
// on a line.
Anything between the symbol pair /* and the
symbol pair */ is considered a comment and is
ignored by the compiler. Unlike the // comments,
/* to */ comments can span several lines,
36. Naming constants
When you initialize a variable inside a declaration,
you can mark the variable so that the program is
not allowed to change its value. To do this, place
the word const in front of the declaration, as
described below:
Syntax
const Type_Name Variable_Name = Constant;
Examples
const int MAX_TRIES = 3;
const double PI = 3.14159;
37. setprecision()
The setprecision function is used to format
floating-point values.
This is a built function and can be used by
importing the iomanip library in a program.
By using the setprecision function, we can
get the desired precise value of a floating-
point or a double value by providing the
exact number of decimal places.
38. 遺或鰻意禽
It can be used to format only the decimal
places instead of the whole floating-point
or double value.
This can be done using the fixed keyword
before the setprecision() method.
Syntax
setprecision(number)
40. setw()
setw function is a C++ manipulator
which stands for set width.
The manipulator specifies the
minimum number of character
positions a variable will consume.
In simple terms, it helps set the field
width used for output operations.
Syntax
setw(number)
42. Class Task
Write a program that plays the game of Mad Lib.
Your program should prompt the user to enter the
following strings:
The first or last name of your instructor
Your name
A food
A number between 100 and 120
An adjective
A color
An animal
43. Contd
After the strings are input, they should be
substituted into the story below and output to the
console.
Dear Instructor [Instructor Name],
I am sorry that I am unable to turn in my homework
at this time. First, I ate a rotten [Food], which made
me turn [Color] and extremely ill. I came down with a
fever of [Number 100-120]. Next, my [Adjective] pet
[Animal] must have smelled the remains of the
[Food] on my homework, because he ate it. I am
currently rewriting my homework and hope you will
accept it late.
Sincerely,
[Your Name]