Introduction to C And C++ Programming - Technology and Tricks

Today the world is rapidly developed in the technology field so everyone wants to know themselves about technology and tricks. In this blog, everyone knows about the latest technology and tricks. This blog contains informational content, latest news, and tricks about technology.

Introduction to C And C++ Programming

Share This

A Simple C++ Program


1 // simple program
2 //Text-printing program. 
3 #include // allows program to output data to the screen 
4 using namespace std;
5 // function main begins program execution 
6 int main()
7 {
cout << "Welcome to C++!\n"; // display message 

10  return 0; // indicate that program ended successfully 
11 } // end function main


Comments

Used to describe program
/* and */ is multiline comment
// is single line comment
Text starting with // or surrounded by /* and */ is ignored by computer

#include
Preprocessor directive
Tells computer to load contents of a certain file
or allows standard input output operations

int main()
C++ programs contain one or more functions, exactly one of which must be main
Parenthesis used to indicate a function
int means that main "returns" an integer value
Braces ({ and }) indicate a block
The bodies of all functions must be contained in braces

cout << “Hello World\n”;

Instructs computer to perform an action
Specifically, prints the string of characters within quotes (“ ”)
Entire line called a statement
All statements must end with a semicolon (;)
Escape character (\)
\n is the newline character
<< insertion operator or put to operator

return 0;
A way to exit a function
return 0, in this case, means that the program terminated normally

Right brace }
Indicates end of main has been reached
Linker
When a function is called, linker locates it in the library
Inserts it into object program
If function name is misspelled, the linker will produce an error because it will not be able to find function in the library


Data Types

  • int
  • float
  • double
  • char
  • bool
  • void


Memory Concept 

Variables 

Variable names correspond to locations in the computer's memory
Every variable has a name, a type, a size and a value
Whenever a new value is placed into a variable (=), it replaces (and destroys) the previous value
Reading variables from memory does not change them


Variable

  • variable can hold a number or a data of other types, it always holds something. A variable has a name
  • the data held in variable is called value
  • variables are implemented as memory locations and assigned certain memory address. The exact address depends on computer and compiler.
  • we think as though the memory locations are actually labeled with variable names

Identifier

identifier – name of a variable or any other named construct
identifier must start with a letter or underscore symbol (_), the rest of the characters should be letters, digits or underscores
the following are legal identifiers:
x    x1 x_1   _abc sum RateAveragE

the following are not legal identifiers. Why?
13  3X  %change  data-1  my.identifier  a(3) 

C++ is case sensitive:
MyVar and myvar  are different identifiers 


7 comments:

  1. I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
    360DigiTMG big data course malaysia

    ReplyDelete
  2. I see the best substance on your blog and I unbelievably love getting them.
    https://360digitmg.com/india/data-science-using-python-and-r-programming-in-delhi

    ReplyDelete

  3. The writer is amped up for purchasing wooden furniture on the web and his examination about best wooden furniture has accomplished the blueprint of this article.
    supply chain management courses

    ReplyDelete
  4. Cognex is the AWS Training in Chennai. Cognex offers many offers during this diwali 2020. Cognex providing courses both in offline and online.

    ReplyDelete

Pages