Search
 
SCRIPT & CODE EXAMPLE
 

CPP

pointers in c++

/*
Here is how pointers work in a nustshell(represent | as what's
happening in the memory and / as a place in the ram):
int x = 2; | 2/0x00ef5
int *z = &x| 0x00ef5/0x00ef6 (See how the value of the pointer z
matches with the memory address of x? that's how they work!)

when you print out the pointer as *n (replace n with the var name)
it will actually look at the value
see it's a memory address
go to that memory address
and print the value originally in the memory address which is 2

Here is code:
*/
int x = 5;
int *y = &x;
cout << *y+1;
/*
the reason why i did *y+1 was so to show that after it got
the value from the memory address it will add 1
*/
Comment

pointers in c++

#include <iostream>

using namespace std;

int main()
{
   int x=5;
   int *ptr=&x;
   cout<<&x<<endl;        //prints the address of the variable (x)
   cout<<ptr<<endl;       //prints the address of the variable (x)
   cout<<*ptr<<endl;      //prints the value of x(5)
   cout<<&ptr<<endl;      //prints the address of the pointer (ptr)
   
   
}
Comment

Pointers in c++

int x = 2;
int *y = &x;

cout << *y;
Comment

C++ Pointers to Structure

#include <iostream>
using namespace std;

struct temp {
    int i;
    float f;
};

int main() {
    temp *ptr;
    return 0;
}
Comment

pointer to pointer c++

#include <iostream>
using namespace std;

struct Distance {
    int feet;
    float inch;
};

int main() {
    Distance *ptr, d;

    ptr = &d;
    
    cout << "Enter feet: ";
    cin >> (*ptr).feet;
    cout << "Enter inch: ";
    cin >> (*ptr).inch;
 
    cout << "Displaying information." << endl;
    cout << "Distance = " << (*ptr).feet << " feet " << (*ptr).inch << " inches";

    return 0;
}
Comment

C++ Pointers to Structure

#include <iostream>
using namespace std;
struct Distance {
    int feet;
    float inch;
};
int main() {
    Distance *ptr, d;
    ptr = &d;
        cout << "Enter feet: ";
    cin >> (*ptr).feet;
    cout << "Enter inch: ";
    cin >> (*ptr).inch;
     cout << "Displaying information." << endl;
    cout << "Distance = " << (*ptr).feet << " feet " << (*ptr).inch << " inches";
    return 0;
}
Comment

pointers in cpp

int *ip; // pointer to an integer
double *dp; // pointer to a double
float *fp; // pointer to a float
char *ch // pointer to character
Comment

pointers in c++

void simple_pointer_examples() {
    int   a;  // a can contain an integer
	int*  x;  // x can contain the memory address of an integer. 
 	char* y;  // y can contain the memory address of a char. 
 	Foo*  z;  // z can contain the memory address of a Foo object.  
 
    a = 10;
    x = &a;   // '&a' extracts address of a 
  
    std::cout <<  x << std::endl; // memory address of a => 0x7ffe9e25bffc
    std::cout << *x << std::endl; //          value of a => 10
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ power of two 
Cpp :: not c++ 
Cpp :: cpp language explained 
Cpp :: find second largest number in array c++ 
Cpp :: even and odd numbers 1 to 100 
Cpp :: C++ Class Template Declaration 
Cpp :: queue 
Cpp :: what destructor used for in c++ 
Cpp :: cpp compare strings 
Cpp :: how to compile c++ code with g+ 
Cpp :: Programming Languages codechef solution in c++ 
Cpp :: java to puthon converter 
Cpp :: c++ how to do a pointer char to take varols from keyboard 
Cpp :: Maximum Weight Difference codechef solution c++ 
Cpp :: how to run cpp in visual studio 
Cpp :: C++ Initializing a thread with a class/object 
Cpp :: how to type a vertical stack program c++ 
Cpp :: what is c++ 
Cpp :: identity 
Cpp :: sort an array using stl 
Cpp :: KL/wweiok#L['.[- 
Cpp :: ternary operator rsut 
Cpp :: c++ iterator shorthand 
Cpp :: Qt asynchronous HTTP request 
Cpp :: convert c++ to c language 
Cpp :: ue4 c++ bool to text 
Cpp :: how to extract a bit from a byte in c++ 
Cpp :: deifine an object in C++ 
Cpp :: quiz arrary and pointers in c++ 
Cpp :: inside information subtask 2 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =