0% found this document useful (0 votes)
12 views7 pages

POINTERS Activity

The document contains C++ code snippets demonstrating the use of pointers. The snippets show: 1) Creating a pointer to an integer variable and checking if the address is the same; 2) Creating a new pointer and assigning it to an existing pointer; 3) Updating the value of a variable using a pointer; 4) Using pointers with floating point values and formatting output; 5) Taking input using pointers and adding two numbers; 6) Assigning a character value to pointers and outputting the value.

Uploaded by

beatriz101177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

POINTERS Activity

The document contains C++ code snippets demonstrating the use of pointers. The snippets show: 1) Creating a pointer to an integer variable and checking if the address is the same; 2) Creating a new pointer and assigning it to an existing pointer; 3) Updating the value of a variable using a pointer; 4) Using pointers with floating point values and formatting output; 5) Taking input using pointers and adding two numbers; 6) Assigning a character value to pointers and outputting the value.

Uploaded by

beatriz101177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

TAGACA CHARLIE Z.

BSCpE 2B

#include<iostream>

using namespace std;

int main(void)

int num = 5;

int *address =&num;

if (address == &num) {

cout << "Address printed!";

return 0;

}
TAGACA CHARLIE Z.
BSCpE 2B

#include<iostream>

using namespace std;

int main(void) {

int num = 5;

int* a = &num;

// TODO: Create a new pointer here

int* b=a;

cout<<"Value: "<< *b << endl;

return 0;

}
TAGACA CHARLIE Z.
BSCpE 2B

#include<iostream>

using namespace std;

int main(void) {

int num = 5;

int* a = &num;

// TODO: Update the value of `num`


using the pointer `a`

*a = 999;

cout<<"Value: "<< num << endl;

return 0;

}
TAGACA CHARLIE Z.
BSCpE 2B

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main (void){

float floatValue;

float* floatPointer = &floatValue;

cout<<"Enter a value: ";

cin>> floatValue;

cout<<"Value: "<< fixed <<


setprecision(1) <<
round(*floatPointer*10) / 10 << endl;

return 0;

}
TAGACA CHARLIE Z.
BSCpE 2B

#include <iostream>

using namespace std;

int main (void){

int num1, num2;

int* pntr1 = &num1;

int* pntr2 = &num2;

cout<<"Enter first integer: ";

cin>> *pntr1;

cout<<"Enter second integer: ";

cin>> *pntr2;

int sum = *pntr1 + *pntr2;

cout<<"Sum of two integers: "<< sum


<< endl;

return 0;

}
TAGACA CHARLIE Z.
BSCpE 2B

#include<iostream>

using namespace std;

int main(void)

char a = 'J';

char ptr1 = a;

char ptr2 = ptr1;

cout << "Value of character = " << ptr2;

return 0;
TAGACA CHARLIE Z.
BSCpE 2B

You might also like