Getting Started 😍

Getting Started:- 


Writing our first program :


In this program, we covered the basic concepts of the Structure of the C++ program, Variables, Input and Output streams. 

Structure of C++ Program:


int main(): 
  • The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return an integer type data.
  • When our program is simple, and it is not going to terminate before reaching the last line of code, or the code is error-free, then we can use the void main().

#include<iostream>: 
  • It is the predefined library function used for input and output also called a header file.
  • iostream is the header file which contains all the functions of program like cout, cin, etc, and #include tells the preprocessor to include these header files in the program.

using namespace std: 
  • Since its creation, C++ has gone through many changes by the C++ standards committee. One of the new features added to this language is a namespace. A namespace permits grouping of carious entities like classes, objects, functions and various C++ tokens, etc., under a single term.
  • Different users can create separate namespaces and thus can use similar names of the entities.
  • This avoids compile-time errors that may exist due to identical name conflicts.

Variables:

  • A variable is an abstraction of a memory location.
  • Allows programmers to use meaningful names and not memory addresses 
  • Variables have their Type(Integer, Real Number, String, Person, Account,...), Value(10, 3.14, "Name",...).
  • Variables must be declared before they are used.
  • A variable value may change.
  • Naming variables can contain letters, numbers, and underscores.
  • Must begin with a letter to underscore.
  • It cannot begin with a number.
  • Cannot use C++ reserved keywords.
  • Cannot redeclare a name in the same scope.
  • Remember that C++ is case sensitive.
  • Be consistent with your naming conventions.
  • myVariableName vs my_Variable_Name
  • Avoid defining names with underscores.
  • Useful meaningful names not too long and not too short.
  • Never use variables before initializing them.
  • Declare variables close to when you need them in your code.

Constants:

  • Like C++ variables it has names, occupies storage, are usually typed. However, their value cannot be changed once declared.
  • There are different types of constants like Literal constants, Declared constants, Constant expressions, Enumerated constants, and Defined constants.



Input and Output:

  • cout: It is the standard output stream that is associated with the standard output device(monitor) and is used to display the output to users.
  • cin: It is the standard input stream that is associated with the standard input device(keyword) and is used to take the input from users.



Section Challenge:

Create a C++ program that asks the user for their favorite number between 1 to 100 to read this number in the console.
  • Suppose the user enters 24.
Then display following to the console.
  • $Amazing!! That's my favourite number too!
  • $Not really!! 24 is my favourite number!

Comments

Popular posts from this blog

Basic things You need to Know in C++😁

Arrays and Vectors ❤️