Functions in C/C++

 // Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;


// int add(int,int);

int add(int a,int b); // 'a' and 'b' are formal parameters;

int sub();

void dis(int a);

void easter();

void change(int *x){

    *x=77;

}


void changer(){

    static int a=12;

    a++;

    cout<<"The value of a is :- "<<a<<endl;

}


inline int sqr(int x){

    return x*x;

}


// functions returning pointer

int* actual(int *a){

    return a;

}



int main() {

    // Write C++ code here

    cout<<add(12,12)<<endl; // here 12 and 12 are actual parameters;

    cout<<sub()<<endl;

    dis(12);

    easter();

    int x=97;

    cout<<x<<endl;

    change(&x);

    cout<<x<<endl;

    cout<<endl<<endl;

    changer();

    changer();

    cout<<sqr(3)<<endl;

    int *ptr=&x;

    cout<<*actual(ptr)<<endl;

    printf("%d\n",*ptr);

    


    return 0;

}


int add(int a,int b){

    return a+b;

}

int sub(){

    return 1+9;

}

void dis(int a){

    cout<<"Display all"<<endl;

}


void easter(){

    cout<<"Easter Day Celebration!"<<endl;

}

Comments

Popular posts from this blog

Requests and Urllib

Strings in C Language

Dictionary in Python