Computer Science, asked by Anonymous, 1 year ago

Hey❤

⭐❤Give C++ statements to do the following :

(i) Create a character pointer

(ii) Make this character ptr hold the address of integer variable var❤⭐​

Answers

Answered by himanshurana8529
7

Hello!!!!

#include <iostream>

using namespace std;

int main() {

int a = 32, *ptr = &a;

char ch = 'A', &cho = ch;

cho += a;

*ptr += ch;

cout << a << ", " << ch<<endl;

return 0; }

Explanation:

The “ptr” variable is a pointer which holds the address of variable “a”. And “*ptr” returns the value of “a” variable. “cho” is a reference variable to “ch”. So any change made to “cho” will be reflected to “ch”. As such, when “cho” is increased by 32, it adds to the ASCII value of “A”(which is 65), and this results to 97 which is the ASCII value of “a”(from the alphabet). So this “a” gets stored in “ch”. As for when “*ptr” is incremented by “ch”, it gives value 97+32=129

Thanks


Anonymous: Thanks
Answered by swaggerCRUSH
3

#include <iostream>

using namespace std;

int main () {

const char *str = "how are you\n";

int i[]={1,2,3};

cout << str << endl; // << is defined on char *.

cout << i << endl;

cout << *str << endl;

}

OUTPUT:

how are you

0xbfac1eb0


Anonymous: Thanks❤⭐✌
Similar questions