DATA STRUCTURE AND ALGORITHAM
1. DEFINITION OF POINTER
In simple word, " Pointer is Variable whose value is the address of another variable. i.e it can store the direct address of the memory location. In the declaration of any Variable, we mention the data -type of Variable (int, float, etc).
SYNTAX OF POINTER :
type *var-name;
Here type is the data-type of pointer-variable, and Symbol (*) is called Asterisk.
These are some Valid Pointer:-
int *p; // pointer to an Integer.
double *p; // Pointer to a double.
float *p; // Pointer to a float.
char *p; // Pointr to characher
Let int *p;
int x = 5;
Here If we want to store the Address of x then we have to use
p = &x;
because Ordinary variable can't Store the Address of any Variable.
Some Problem of Pointer
1. PROBLEM 1.
#include<stdio.h>
int main()
{
int *j; //Here j pointer varible//
int x=2;
j=&x; // variable j store the address of x
printf("%d\n",x); // It prints the value of x i.e 2
printf("%u",&x); // It prints the Address of x
printf("\n%u",j);
//we can't store value of x in ordinary
// varible,so we use *j is not an
// ordinary variable
// It also gives address of x.
printf("\n%u",*j); // *j=x
return 0;
}
Some Important Conversion :
-
string to int string str = "123"; int x = stoi(str); // x = 123 -
int to string int x = 5; string str = to_stream(x) // str = "5"

Comments
Post a Comment