1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mila [183]
3 years ago
15

What is the basics of C++

Computers and Technology
1 answer:
arlik [135]3 years ago
3 0
Here are the basics of C++...

Number 1. Printing text onto the screen:
std::cout << "Your text here\n"; 
The \n creates a new line.

Number 2. Initializing variables and setting variables
There are a few different types of variables in C++...
Integers, floats, chars, and strings.
To let C++ know what type of variable you are about to create, you put the type before the variable name.

Here are some examples:
int number = 10;
float r = 2.45;
char[4] = "Code";
string name = "Bob";

Number 3. Comments

In programming comments are very useful. They help other programmers understand your code.

To make a single line comment in C++ you do this:

// your comment

To make a multi-line comment in C++ you do this:

/*
My multi-line comment here
*/

Number 4. Math

In C++ you have math operators. These operators are + - * / %
I'm pretty sure you are familiar with the first four operators. But you may not know the last one. Don't worry... I'll explain that one to you.

Addition:

std::cout << 35 + 23 // this will print out 58

Subtraction:

std::cout << 102 - 56; // this will come out as 46

Multiplication:

std::cout << 34 * 9; // product will be 306

Division:

std::cout << 164 / 4; // quotient will be 41

Modulus:

Now we get to the operator you may or may not know. The modulus.
The modulus operator gets the remainder of division of a by b.

std::cout << 10 % 4; // it will print out 2

You can even store math operations in variables...

int answer = 40 + 38;
std::cout << answer; // this will print out 78

You can even add variables...

int x = 28;
int y = 58;
int answer = 86;
std::cout << answer;
std::cout << x + y;

Number 5. Comparison Operators.

Comparison operators compare two values to see if its true or false...
These are mainly used in if statements...

Here are the comparison operators:

== Equal
!= Not equal
> Greater than
< Less than
<= Less or equal
>= Greater or equal

Number 6. If Statements

This is the structure of an if statement:

if(...){
// execute code if true
} else if(...){
// execute this block of code if first if statement was false
}else {
// execute this block of code if false
}

if(2 > 1) {
std::cout << "2 is greater than 1";
}

The code above will indeed execute. Because two is greater than 1.

Number 7. Functions

If you have a block of code that will be repeated multiple times through out your program, functions will be handy.

To make a function you must specify the type of the function. This called the return type.
Which are int (integers), floats (decimals), and string (strings).
There are more, but I decided to focus on those three.

Then you give your function a name. 

int my_function(){
// your code
}

To call a function, you simply type the name of the function with parentheses.

my_function();

To make a function with parameters, do same thing above, except in the parentheses you give your parameters.

int my_function(int x, int y){
// your code
}

As you can see, you separate the parameters with a comma.

in my_function(int x, int y){
int z = x + y;
std::cout << z; // this will print out the sum of x and y
}

To call your function with parameters, type your function name with parentheses and in the parentheses type your values.

my_function(3, 4); // this will print out 7

Also, another type of function is the void type. In int type functions, at the end of your code in the function, you should type return 0.
This allows C++ know that code wen't without any errors...

In void type function this isn't really necessary...

If you have anymore questions or you found something to be confusing or you want to learn more C++, please write me a message.



You might be interested in
The measure of the maximum amount of data that can travel through a computer’s communications path in a given amount of time is
STatiana [176]

Answer:

Bandwidth

Explanation:

Bandwidth is the rate of transfer of data in the given time. Its unit is Bit/sec.

It is used to measure the transfer rate of bit in a network.

4 0
3 years ago
Which type of service offers a preconfigured testing environment for application developers to create new software applications
gtnhenbr [62]

The type of service offers a preconfigured testing environment for application developers to create new software applications is Software as a Service (SaaS).

<h3>What is software as a service SaaS?</h3>

Software as a service (SaaS) is known to be a type of service that gives its users the ability to be able to link to and also use cloud-based apps in course of the Internet.

Conclusively, The type of service offers a preconfigured testing environment for application developers to create new software applications is Software as a Service (SaaS) as it gives its best service.

Learn more about application developers  from

brainly.com/question/11352260

#SPJ1

5 0
2 years ago
Which phrase best describes a scenario in Excel 2016?
Airida [17]

Answer:

what are the phrases?

Explanation:

6 0
3 years ago
Which image property helps to create distinction between the highlights and shadows of an object?
Nutka1998 [239]
I know filters, so I know it is Saturation.
6 0
3 years ago
Read 2 more answers
Which font is most suitable for an academic article on a website? Which is most suitable for casual information?
CaHeK987 [17]

There are thousands of fonts, there is no clear answer of what is best for ___ website or ___ page. It's all what you think looks good and sometimes depends on the colors on the site.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Which change signaled a musical progression toward rock and roll?
    14·1 answer
  • Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
    11·1 answer
  • Americans overwhelmingly support organ and tissue donation.
    5·1 answer
  • By generating and delivering timely and relevant information supported by networks, _____ creates new opportunities for conducti
    15·1 answer
  • Use the Internet and other sources to research the two disadvantages of standard biometrics: cost and error rates. Select one st
    10·1 answer
  • Rewrite each condition below in valid Java syntax (give a boolean expression): a. x &gt; y &gt; z b. x and y are both less than
    7·1 answer
  • Hey, how is everyone????????????????????????????????
    8·2 answers
  • 69696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969696969
    8·1 answer
  • (C) Describe about the different types of computer<br> peripherals and memory devices.
    9·1 answer
  • HELP PLEASE
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!