Giter Site home page Giter Site logo

c-plus-plus's Introduction

C PLUS PULS

       .:^^::.                                
    :7JYYYYYYY^     ...         ...           
   ~YYYJ~^^^!!     .JY7        .JY7           
  :YYYY:        :^:^YY?::^. :^:^YY?::^.       
  ^YYYJ         ?YYYYYYYYY! ?YYYYYYYYY!       
  .JYYY~     .  ...:Y5?.... ...:Y5?....       
   ^JYYY?777?J.    .7?!        .7?!           
    .^7?JJJJ?7.                               

White Minimalist Photography Channel Youtube Intro

AUTHORS Logo

WHAT YOU GET FORM THIS GITHUB Awesome

  • ALL BASIC CODE OF C++
  • WITH OUTPUT
  • FOR EDUCATION PORPUSE ONLY

CODES Logo

first c++ program

CODE

 #include <iostream>
 using namespace std;
int main()
{
    cout<< "Hello World";
    return 0;
}

OUTPUT

Hello  World 

LOOPS

  • For loop
  • While loop
  • do while

for loop

  • SYNTEX
for (initialise counter; test counter; increment / decrement counter)
{
    //set of statements
}
  • EXAMPLE
#include <iostream>
using namespace std;
 
int main()
{
    int num = 10;
    int i;
    for (i = 0; i < num; i++)
    {
        cout << i << " ";
    }
    return 0;
}
  • OUTPUT
Output :
0 1 2 3 4 5 6 7 8 9

while loop

  • SYNTEX
while (condition test)
{
    // Set of statements
}
  • EXAMPLE
#include <iostream>
 using namespace std;
int main() {
    int n,i=1;
    cout << "Enter a number: ";
    cin >> n;
    
    while (i <= n) {
        cout << i << " ";
        i++;
    }

    return 0;
}
  • OUTPUT
Output : // n= 5;
Enter a number: 6
1 2 3 4 5 6 

do while

  • SYNTEX
do
{
    statements;
} while (test condition);
  • EXAMPLE
#include <iostream>
using namespace std;

int main()
{
    int i = 1, n;

    cout << "Enter the range of numbers: ";
    cin >> n;

    do
    {
        cout << i << endl;
        i++;
    } while (i <= n);

    return 0;
}
  • Output
Output : // n=5;
Enter the range of numbers: 5
1
2
3
4
5

UNION

basic example in short

  • CODE
#include<iostream>
using namespace std;
union magic
{
    int age;
    float rice;
    char name;
}; 
int main(){
    union magic guru;
    guru.age =34;
   // guru.rice=495.56;
    cout<<"the value of guru age is :"<<guru.age<<endl;
    //cout<<"the value of guru rice is :"<<guru.rice<<endl;
    
}
  • OUTPUT
the value of guru age is :34

union example 2

  • CODE
  #include <iostream>
#include <string.h>
using namespace std;
union Employee {
int emp_id;
char emp_name[30];
float salary;
}info;
int main(){
info.emp_id = 34;
strcpy( info.emp_name, "Raj Biradar");
info.salary = 20000.00;
cout<<"Employee id is : "<<info.emp_id<<endl;
cout<<"Employee name is : "<<info.emp_name<<endl;
cout<<"Employee salary is : "<<info.salary<<endl;
return 0;
}
  • OUTPUT
Employee id is : 1184645120
Employee name is :
Employee salary is : 20000

FUNCTION

sum of two number using function

  • CODE
#include<iostream>
using namespace std;
int sum(int a ,int b){
    int c=a+b;
    return c;
}
int main(){
    int num1,num2;
    cout<<"enter the first value"<<endl;
    cin>>num1;
    cout<<"enter the second value"<<endl;
    cin>>num2;
    cout<<"the result is : 56"<<sum(num1,num2)<<endl;    
    return 0;

} 
  • OUTPUT
enter the first value
56
enter the second value
10
the result is : 66

function calling

  • CODE WITH EXPANATION
  #include<iostream>
using namespace std;

int sum(int a, int b){
    int c = a + b;
    return c;
}

// This will not swap a and b
void swap(int a, int b){ //temp a b
    int temp = a;        //4   4  5   
    a = b;               //4   5  5
    b = temp;            //4   5  4 
}

// Call by reference using pointers
void swapPointer(int* a, int* b){ //temp a b
    int temp = *a;          //4   4  5   
    *a = *b;               //4   5  5
    *b = temp;            //4   5  4 
}

// Call by reference using C++ reference Variables
// int & 
void swapReferenceVar(int &a, int &b){ //temp a b
    int temp = a;          //4   4  5   
    a = b;               //4   5  5
    b = temp;            //4   5  4 
    // return a;
}

int main(){
    int x =4, y=5;
    // cout<<"The sum of 4 and 5 is "<<sum(a, b);
    cout<<"The value of x is "<<x<<" and the value of y is "<<y<<endl;
    // swap(x, y); // This will not swap a and b
    // swapPointer(&x, &y); //This will swap a and b using pointer reference
    swapReferenceVar(x, y); //This will swap a and b using reference variables
    // swapReferenceVar(x, y) = 766; //This will swap a and b using reference variables
    cout<<"The value of x is "<<x<<" and the value of y is "<<y<<endl; 
    return 0;
}
  • OUTPUT
The value of x is 4 and the value of y is 5
The value of x is 5 and the value of y is 4

fuction overloding

  • CODE
#include<iostream>
using namespace std;
int sum(int a, int b){
    int c=a+b;
    return c;
}
int sum(int a, int b , int c){
    return(a+b+c);
}
/*int volume(float a,int r){
    return(3.14*r*r);
}
int area(float l, float b){
    return(l*b);
}*/
int main(){
    cout<<"result of sum --> "<<sum(10,20)<<endl;
    cout<<"result of sum three numbers --> "<<sum(10,20,10)<<endl;
   // cout<<"result of volume --> "<<volume(2,20)<<endl;
    //cout<<"result of area -->"<<area(10,20)<<endl;

}
  • OUTPUT
result of sum --> 30
result of sum three numbers --> 40

c-plus-plus's People

Contributors

gurumukhprajapati avatar mansichanal663 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.