Saturday, 10 April 2021

Function in C and C++ Qus 3

 #include<stdio.h>

#include<conio.h>

//#include<iostream.h>

void show(int a);

void show(int a,int b);


void show(int a)

{

printf("%d",a);

}

void show(int a,int b)

{

printf("\n%d",(a+b));

}

int main()

{

clrscr();

show(5);

show(8,3);


getch();

return 0;

}

Function in C and C++ Qus 2

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

int sum(int a,int b);

int sub(int a,int b);

int main()

{

clrscr();

cout<<sum(6,3)<<endl;

cout<<sub(6,3)<<endl;

int s=sum(9,5);

cout<<s<<endl;

getch();

return 0;

}

int sum(int a,int b)

{

cout<<"Sum="<<a+b<<endl;

return a+b,a*b;

}

int sub(int a,int b)

{

return a-b;

}

Function in C and C++ Qus 1

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

//void show();

void show()

{

cout<<"Show-1";

}

int main()

{

clrscr();

show();

//int a=show();

//cout<<endl<<a;

getch();

return 0;

}

/*

void show()

{

cout<<"Show";

}

*/

Pointer in C and C++ Qus 8

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

int main()

{

clrscr();

int A[2][4]={3,6,9,12,15,18,21,24};

cout<<-A[1][2]<<endl<<-2[1[A]];

cout<<endl<<A[1]<<endl<<*(A+1)<<endl;

cout<<*(A[1]+2)<<endl<<*(*(A+1)+2);



getch();

return 0;

}

Thursday, 8 April 2021

Pointer in C and C++ Qus 7

 #include<stdio.h>

#include<iostream.h>

#include<conio.h>

int main()

{

clrscr();

int a=5;

int *p;

p=&a;

cout<<a<<endl;

cout<<++a<<endl;

cout<<p<<endl;

cout<<++p<<endl;

int b=7;

const int *q;

q=&b;

//cout<<q<<endl;

cout<<b<<endl;

cout<<++b<<endl;

int const  *r ;

r=&b;

//cout<<r;

//cout<<q<<endl;

//cout<<++q<<endl;


const int c=5;

const int * const m=&c;

//m=&c;

//*m=10;

const int * n;

n=&c;

++n;

int d=5;

int * const o=&d;

//o++;

d++;

//*o++;

++(*o);

//o=&c;

int const *s=&d;

s++;

d++;

*s++ ;

*s=10;

getch();

return 0;

}

Pointer in C and C++ Qus 6

 #include<stdio.h>

#include<iostream.h>

#include<conio.h>

int main()

{

clrscr();

int A[3][3]={{1,2,3},{4,5,6},{7,8,9}};

int a=5;

int *p;               //pointer to int

p=&a;

int **q;              //pointer to pointer to int

q=&p;

cout<<A<<endl;           //Base Add

cout<<p<<endl;

int (*r)[3];

r=A;

/*cout<<A[0]<<endl;          //Base Address

cout<<A+1<<endl;

cout<<A[0]+1<<endl;

cout<<A[0][0]<<endl;

cout<<A[1]<<endl;

cout<<A[1]-A[0]<<endl;

cout<<A[2]<<endl;

*/

cout<<A[0][0]<<endl<<*(*(A+0)+0)<<endl;    //*(*(A+i)+j)  =A[i][j]

cout<<A[0]<<endl<<*(A+0)<<endl;            //*(A+i)=A[i]

cout<<A[1]<<endl<<*(A+1);

int *s;

s=&A[0][0];

getch();

return 0;

}

Tuesday, 6 April 2021

Pointer in C and C++ Qus 5

 #include<stdio.h>

#include<iostream.h>

#include<conio.h>

main()

{

clrscr();

int a=5;

int *p=NULL;      //scalar address , address of litral not allowed

cout<<p<<endl<<*p;

int *q=0;          //A NULL pointer is a pointer that does not point

// to any memory location. It store the base address of the segment


cout<<endl<<q<<endl<<*q;

//int *r=nullptr;

//int *r=null;

getch();

return 0;

}

Poniter in C and C++ Qus 4

 #include<stdio.h>

#include<iostream.h>

#include<conio.h>

main()

{

clrscr();

int a=5;

char c='k';

float f=9.6;

int *p=&a;

char *q=&c;

float *r=&f;

cout<<*p<<endl<<*q<<endl<<*r<<endl;

cout<<sizeof(p)<<endl<<sizeof(q)<<endl<<sizeof(r)<<endl;

cout<<p<<endl<<&q<<endl<<r<<endl;


getch();

return 0;

}

Poniter in C and C++ Qus 3

 #include<stdio.h>

#include<iostream.h>

#include<conio.h>

main()

{

clrscr();

int a=5,b=10;

int *p,*q;

q=&b;

p=q;

cout<<p<<endl;

cout<<q<<endl;

cout<<&a<<endl;

cout<<&b<<endl;

b=a;

cout<<a<<endl;

cout<<b<<endl;

cout<<*p<<endl;

cout<<*q<<endl;

getch();

return 0;

}

Pointer in C and C++ Qus 2

 

#include<stdio.h>

#include<iostream.h>

#include<conio.h>

main()

{

clrscr();

int a=5,b=10;

int *p;

*p=b;

cout<<&a<<endl;

cout<<&b<<endl;

cout<<p<<endl;

cout<<*p<<endl;

cout<<a<<endl;

cout<<b<<endl;

getch();

return 0;

}