Computer Programming is followed by the name of the header
file that is enclosed in angle brackets, <
C is a successor of Basic Combined and >
Programming Language' (BCPL) called B
language which was introduced around Namespace
the early 1970s. Namespace is not available in a C
C was invented to write an operating program but available in a C++
system called UNIX. program. It is used to organize different
The C language was originally designed names used in programs.
to support procedure-oriented
programming. Function
It was subsequently extended to C++ to
support object-oriented programming A function is a group of related
(OOP). instructions, also called statements,
The symbol ++ in C++ indicates that it which together perform a particular task.
is an extension of C Translating the Code for the Computer
C programming is a general-purpose,
procedural, imperative computer Three programs are used to translate the
programming language developed source code into an executable file that
in 1972 by Dennis M. Ritchie at the the computer can run. They are the
Bell Telephone Laboratories to preprocessor, compiler, and linker
develop the UNIX operating system. program.
C++, which was an extension of C The preprocessor is a program that
language was designed by Bjarne scans the source code for preprocessor
Stroustrup in 1985. The compiler is another program that
ANSI. American National Standards translates the preprocessed source code
Institute (ANSI) is a private non-profit into corresponding machine language
organization that oversees the instructions, which are stored in a
development of voluntary consensus separate file, called an object file, having
standards for products, services, a .obj extension.
processes, systems, and personnel in the The linker is a third program that
United States. combines the object file with the
C++. C++ is a general-purpose necessary parts of the run-time library.
programming language created by
Bjarne Stroustrup as an extension of the Memory and Data Types
C programming language, or "C with Data is the information that is the
Classes". subject of the program.
Dennis Ritchie. Dennis MacAlistair Memory is used to store and recall
Ritchie (September 9, 1941 – c. information.
October 12, 2011) was an American Information, also called data, comes in
computer scientist who created the different forms. The type of data,
C programming language and, with whether numeric, text or something else
long-time colleague Ken Thompson, the is referred to as the data type.
Unix operating system and B
programming language. Data Types
UNIX. UNIX is a family of multitasking,
multiuser computer operating systems The ones and zeros that may be stored
that derive from the original AT&T Unix, at a memory address may represent text
development starting in the 1970s at the and a whole number.
Bell Labs research center by Ken
Whole Number Data Types
Thompson, Dennis Ritchie, Brian
There are several different whole-
Kernighan, Douglas McIlroy, and Joe
number data types. The listed sizes
Ossanna.
and range are typical but may vary
Comment Line depending on the compiler and
operating system.
The comment line is part of the source Unsigned vs. Signed Data Type
code disregarded by the compiler and Unsigned means the number is
does not have any effect on the behavior always zero or positive, never
of the program. negative.
Size
Preprocessor Directive all C++ data types have a size. A
#include is an example of an include byte is the smallest unit of
directive and it is called a preprocessor information that a computer can
directive. Preprocessor directive lines process, no data type may be smaller
always begin with a pound sign (#) and than one byte.
Range the sizeof(int) expression. A special type of
range means the highest and lowest string is called an escape sequence.
value that may be represented by a
given data type. Declaring Variables - The information
Storage a program uses while it is running first
A memory address can hold only 8 needs to be stored in memory.
bits or a byte. Syntax of Declaring Variables - It is a
Floating-Point Data Types must to declare variables before using
Whole numbers work fine for certain them. Name is an alias by which you can
information where fractions don’t refer in code to the area of reserved
apply. Whole numbers also work fine memory.
for certain information where Declaring Multiple Variables of the
fractions do apply but are not Same Data Type - Several variables of
important. the same data type could be declared in
Text Data Types a separate statement.
There are two text data types. The Naming Variables - Variables have
first is char, which stands for names that are used to identify the
character. It is usually is 1 byte, and variable so you can refer to it in code. It
can represent any single character, is also known as identifiers.
including a letter, a digit, a Scope of A Variable - A variable can be
punctuation mark, or a space. The either of global or local scope. A global
second text data type is a string. The variable is a variable declared in the
string data type may store several main body of the source code, outside all
characters, including a sentence, or functions.
paragraph, or page. Naming Conventions - The naming
Boolean Data Types convention is simply a consistent
The bool data type has only two method of naming variables.
possible values, true and false, and
The Address Operator
its size usually is one byte. The term
“bool” is a shortening of Boolean, Declaring a variable reserves memory.
which is usually used in connection Use the address operator (&) to learn the
with Boolean Algebra, named after address of this reserved memory.
the British mathematician, George
Boole Assigning Values to Variables
Size of Operator The purpose of a variable is to store
information.
The size of operator is followed by parentheses,
in which you place a data type. It returns the Assignment Operator
size in bytes of that data type.
Use the assignment operator to assign a
Expressions value to a variable.
The code sizeof(int) is called an expression. An Assigning a “Compatible” Data Type
expression is a code statement that has a value,
The value assigned to a variable must be
usually a value that has to be evaluated when
compatible with the data type of the
the program runs.
variable that is the target of the
Outputting Expression assignment statement.
The expression sizeof(int)is
Overflow and Underflow
separated by the stream insertion
operator (<<) from the literal string Overflow occurs when a variable is
“Size of int is ”. assigned a value too large for its range.
Escape Sequence Using the cin Operator
The string “\n” following the expression Use the cin object to obtain information
sizeof(int) is also a literal string, so it, from standard input, which usually is the
too, is separated by a stream insertion keyboard. It is defined in the standard
operator from the sizeof(int) expression. library file .
A special type of string is called an
escape sequence.\ Assigning a “Compatible” Data Type
Variables The value being assigned by the cin
operator need not necessarily be the
The string “\n” following the expression same data type as that of the variable to
sizeof(int) is also a literal string, so it, too, is which the value is being assigned.
separated by a stream insertion operator from
Assigning a “Compatible” Data Type
The value being assigned by the cin Exponent
operator need not necessarily be the
same data type as that of the variable to C++, unlike some programming
which the value is being assigned. languages, does not have an exponent
operator. Instead, it has a built-in
Arithmetic Operators function named pow, which is defined in
the standard library file math.
Many computer programs need to
perform calculations. Computers, in Change Machine Program
addition to being able to store vast
amounts of data, also can calculate far Create the flowchart and pseudocode of
more quickly and accurately than a a program that will ask the user to input
human can. the number of 5-centavos. The code
% operator, also called the modulus then will determine and display the
operator, returns the remainder in the equivalent number of twenty pesos, 10
division. pesos, 5 pesos, 1 peso, 25-centavos, 10-
centavos and 5-centavos from the user
input. (P20 = 400pcs of 5¢, P10 =
200pcs of 5¢, P5 = 100pcs of 5¢, P1 =
20pcs of 5¢, 25¢ = 5pcs of 5¢, 10¢ =
2pcs of 5¢ and 5¢ = 1pc of 5¢)
Adding strings
Adding two strings has the effect of
appending the second-string operand to
the first-string operand
The Subtraction Operator
The effect of overflow and underflow is
the same with the subtraction operator
as with the addition operator.
The Multiplication Operator The
Multiplication Operator
The effect of overflow and underflow is
the same with the multiplication
operator as with the addition and
subtraction operators
The Modulus Operator
Modulus operator also involves division
but returns only the remainder. Modulus
operator works only with whole number
operands.