Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Programming: Understanding the Basics and Compilation Process, Study notes of Computer Programming

An introduction to C++ programming, focusing on its advantages, compilation process, and basic language features. It covers topics such as variables, input, and the role of tokens and operators. Students will also learn about the different data types and their sizes and ranges.

What you will learn

  • What are the advantages of using C++ over other programming languages?
  • What are the different data types in C++ and what are their sizes and ranges?
  • What is the compilation process for a C++ program?
  • How do operators work in C++?
  • What are the different types of tokens in C++?

Typology: Study notes

2021/2022

Uploaded on 12/17/2022

jabin-jorvina
jabin-jorvina 🇵🇭

1 document

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C++
ABBY KATE C. ORIOQUE
2022
Instructor 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download C++ Programming: Understanding the Basics and Compilation Process and more Study notes Computer Programming in PDF only on Docsity!

C++

ABBY KATE C. ORIOQUE

2022

Instructor 1

Contents

Compiled Languages and C++

Hello World

Basic Language Features

Variables

Input

The Compilation Process

Source File

Source File

Object File

Object File

Executable Program inMemory

Linker Libraries

OS

Compiler

Compiler

Downloading IDE

Steps:

  1. Go to this site

Downloading IDE

Steps:

  1. Download the installers

Downloading IDE

Steps:

  1. Click the suggested link, then save.

Downloading IDE

Steps:

  1. Launch and open

Click “New Project”

Hello World

// A Hello World program

include < iostream >

int main () { std :: cout << " Hello , world !\ n "; return 0; }

Tokens!

Tokens are the minimals chunk of program that have meaning to the compiler – the smallest meaningful symbols in the language. Our code displays all 6 kinds of tokens, though the usual use of operators is not present here:

Token type Description/Purpose Examples

Operators Mathematical or logical operations

Punctuation/Separators Punctuation defining the structure of a program

Whitespace Spaces of various sorts; ignored by the compiler

Spaces, tabs, newlines, comments

Line-By-Line Explanation

  1. // (Double forward-slash)

● Indicates that everything following it until the end of the line is a comment: it is ignored by the compiler.

● Another way to write a comment is to put it between /* and */

e.g. x = 1 + /sneaky comment here/

● A comment of this form may span multiple lines. Comments exist to explain non-obvious things going on in the code. Use them: document your code well!

Line-By-Line Explanation

cout << : This is the syntax for outputting some piece of text to the screen. We’ll discuss how it works later!

Namespaces: In C++, identifiers can be defined within a context – sort of a directory of names – called a namespace. When we want to access an identifier defined in a namespace, we tell the compiler to look for it in that namespace using the scope resolution operator (::). Here, we’re telling the compiler to look for cout in the std namespace, in which many standard C++ identifiers are defined.

A cleaner alternative is to add the following line below line 2: using namespace std ;

This line tells the compiler that it should look in the std namespace for any identifier we haven’t defined. If we do this, we can omit the std:: prefix when writing cout. This is the recommended practice.

Line-By-Line Explanation

Strings: A sequence of characters such as Hello, world is known as a string. A string that is specified explicitly in a program is a string literal.

Escape sequences: The \n indicates a newline character. It is an example of an escape sequence – a symbol used to represent a special character in a text literal. Here are all the C++ escape sequences which you can include in strings:

Line-By-Line Explanation

return 0 indicates that the program should tell the operating system it has completed successfully. This syntax will be explained in the context of functions; for now, just include it as the last line in the main block. 4

Note:

Every statement ends with a semicolon (except preprocessor commands and blocks using {}). Forgetting these semicolons is a common mistake among new C++ programmers.

Values and Statements

  • A statement is a unit of code that does something – a basic building block of a program.
  • An expression is a statement that has a value – for instance, a number, a string, the sum of two numbers, etc. 4 + 2, x - 1, and "Hello, world!\n" are all expressions.

Note: Not every statement is an expression. It makes no sense to talk about the value of an #include statement, for instance.