C/C++ Introduction PDF

Document Details

GratefulSwan3091

Uploaded by GratefulSwan3091

University of Papua New Guinea

Tags

C++ programming C++ data types programming fundamentals

Summary

This document introduces C/C++ programming by covering fundamental concepts like data types, variables, and operators. It explains how data is stored and manipulated in a computer program.

Full Transcript

C/C++ Introduction Data -- Data refers to any information that is stored in a computer or retrieved after processing. Data can be a character, decimal or a graphic. Variables- A variable is a container where the data you entered is stored, retrieved, or passed on from one part of the program to an...

C/C++ Introduction Data -- Data refers to any information that is stored in a computer or retrieved after processing. Data can be a character, decimal or a graphic. Variables- A variable is a container where the data you entered is stored, retrieved, or passed on from one part of the program to another. A variable consists of a datatype, a variable name or identifier and a value e.g.: int a=5; Guidelines for variable identifiers  They should start with a letter of English alphabet.  Can be a combination of letters, digits and underscore _ characters.  Spaces, punctuation marks, and symbols should not be a part of the identifier.  Variable names should not be the same as the keywords used in the programming language. Types of variables: Local Variables—Declared and used within a specific function and not outside it. Global Variables – Declared in the main body of code and can be referred at any point in the program. Data types in C/C++ short int -128 to 127 (1 byte) unsigned short int 0 to 255 (1 byte) char 0 to 255 or -128 to +127 (1 byte) unsigned char 0 to 255 (1 byte) signed char -128 to 127 (1 byte) int -32,768 to +32,767 (2 bytes) unsigned int 0 to +65,535 (2 bytes) long int -2,147,483,648 to 2,147,483,647 (4 bytes) unsigned long int 0 to 4,294,967,295 (4 bytes) float single precision floating point (4 bytes) double  double precision floating point (8 bytes) long double extended precision floating point (10 bytes) (Bytes – A unit of storage in machine memory is called a bit and eight bits make one byte.) Note: Unsigned data types can take only zero or positive values. Escape Sequences Characters that follow a backslash \ in the code are called escape sequences. Constants A constant is a fixed value that has a name associated with it. Unlike a variable, the value of a constant never changes during program execution. #define statement is used to define a constant. e.g. #define pi 3.14 Directives At the start of each programs, a statement begins with # symbol is added. e.g.: #include It indicates a directive to the processor that it should load the files from the stdio (standard input/output) library. This helps the program to handle the input and the output. Operators Operator is a symbol that defines the type of operations to be performed. Assignment operator – The operator “=” (is equal to) is called the assignment operator and is used to assign values to variables. The value to the right of the assignment operator is assigned to the left of the assignment operator. e.g. a=b means the value of variable b is copied to variable a. Various categories of operators Arithmetic Operators: Perform fundamental arithmetic operations. + Performs addition - Performs subtraction * Performs multiplication / Performs division % Gives the remainder of a division of the two values, called a modulo Relational Operators: Used to compare two variables or expressions. (Result is a true or false value) == Equal to != Not Equal to > Greater than < Less than >= Greater than or Equal to

Use Quizgecko on...
Browser
Browser