Skip to content

AlFalahTaieb/itstimetolearncplusplus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 

Repository files navigation

itstimetolearncplusplus

Instruction

To compile the code you have to do g++ exemple.cpp -o nameExemple

after that it will produce an executable in the same dir which we can run by doing

./nameExemple

Programs written in assembly languages tend to be very fast, and assembly is still used today when speed is critical.

A Compiler is a program that reads source code and produces a stand-alone executable program that can then be run.

Compiler

A programming language gets compiled (You get a program that is not understandable to humans (unless they learned how to read it)). A scripting language gets evaluated at run-time. There are however interpreters for programming languages and compilers for scripting languages. This is just a rule of thumb that gets it right most of the time.

What is C++ good at?

C++ excels in situations where high performance and precise control over memory and other resources is needed. Here are a few common types of applications that most likely would be written in C++:

  • Video games
  • Real-time systems (e.g. for transportation, manufacturing, etc…)
  • High-performance financial applications (e.g. high frequency trading)
  • Graphical applications and simulations
  • Productivity / office applications
  • Embedded software
  • Audio and video processing

Path of solving a problem

Solve

Typically, good solutions have the following characteristics:

  • They are straightforward (not overly complicated or confusing).
  • They are well documented (especially around any assumptions being made or limitations).
  • They are built modularly, so parts can be reused or changed later without impacting other parts of the program.
  • They are robust, and can recover or give useful error messages when something unexpected happens.

There are many different kinds of statements in C++:

Declaration statements

Jump statements

Expression statements

Compound statements

Selection statements (conditionals)

Iteration statements (loops)

Try blocks

☠️☠️☠️☠️☠️

Every C++ program must have a special function named main (all lower case letters). When the program is run, execution starts with the first statement inside of function main and then continues sequentially.

std::cin and std::cout always go on the left-hand side of the statement.

std::cout is used to output a value (cout = character output)

std::cin is used to get an input value (cin = character input)

<< is used with std::cout, and shows the direction that data is moving (if std::cout represents the console, the output data is moving from the variable to the console). std::cout << 4 moves the value of 4 to the console

>> is used with std::cin, and shows the direction that data is moving (if std::cin represents the keyboard, the input data is moving from the keyboard to the variable). std::cin >> x moves the value the user entered from the keyboard into x

Undefined Behavior

Your program produces different results every time it is run.

Your program consistently produces the same incorrect result.

Your program behaves inconsistently (sometimes produces the correct result, sometimes not).

Your program seems like its working but produces incorrect results later in the program.

Your program crashes, either immediately or later.

Your program works on some compilers but not others.

Your program works until you change some other seemingly unrelated code.

A statement is a type of instruction that causes the program to perform some action. Statements are often terminated by a semicolon.

A function is a collection of statements that execute sequentially. Every C++ program must include a special function named main. When you run your program, execution starts at the top of the main function.

Why we use functions ?

Reusability once a function is written, it can be written, it can be called a multiple times from within the probability of copy/pase errors.

When a function becomes too long, too complicated, or hard to understand, it can be split into multiple sub-functions. This is called refactoring.

Words of advice when writing programs

Keep your progrms simple to start Add features over time. Focus on one area at a time Test each piece of code as you go

QuizTime

What is a statement?

A statement is an instruction in a computer program that tells the computer to perform an action.

### What is a function?

A function is a collection of statements that executes sequentially.

What is the name of the function that all program must have?

main

When a program is run, where does execution start?

Execution starts with the first statement inside the main function.

What symbol are statements in C++ often ended with?

The semicolon (;)

What is a syntax error?

A syntax error is a compiler error that occurs at compile-time when your program violates the grammar rules of the C++ language.

What is the C++ Standard Library?

A library file is a collection of precompiled code that has been “packaged up” for reuse in other programs. The C++ Standard Library is a library that ships with C++ that contains additional functionality to use in your programs.

What is data?

Data is any sequence of symbols (numbers, letters, etc…) that can be interpreted to mean something.

What is a value?

A value is a single piece of data stored in memory.

What is a variable?

A variable is a named region of memory.

What is an identifier?

An identifier is the name that a variable is accessed by.

What is a type?

A type tells the program how to interpret a value in memory.

What is an integer?

An integer is a number that can be written without a fractional component.

What is the difference between initialization and assignment?

Initialization gives a variable a value at the point when it is created. Assignment gives a variable a value at some point after it is created.

What is an uninitialized variable? Why should you avoid using them?

An uninitialized variable is a variable that has not been given a value by the program (generally through initialization or assignment). Using the value stored in an uninitialized variable will result in undefined behavior.

What is undefined behavior, and what can happen if you do something that exhibits undefined behavior?

Undefined behavior is the result of executing code whose behavior is not well defined by the language. The result can be almost anything, including something that behaves correctly.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages