0

C++

How to delare pointer in c++

1st Mar 2021, 4:09 AM
Aminu Abdulkadir
Aminu Abdulkadir - avatar
7 Answers
+ 5
Aminu Abdulkadir by putting * (asterisk) between type and variable identifier (name): int *my_int; or: int * my_int; or: int* my_int; would declare a pointer to an int ^^
1st Mar 2021, 4:13 AM
visph
visph - avatar
+ 4
Pointers can be initialised to NULL, which is good practice, if you're not immediately assigning the address of a memory block to it.
1st Mar 2021, 4:32 AM
Sonic
Sonic - avatar
+ 4
It depends on whether the pointer points to an integer (int*), character(char*), float(float*), double(double*) etc.
1st Mar 2021, 4:33 AM
Sonic
Sonic - avatar
+ 3
Your thread will look better if you move the title text 'C++' into the tags, and the Description text 'How to declare pointer in C++' in the question title 👍
1st Mar 2021, 5:31 AM
Ipang
+ 1
however, you need to assign a valid memory address to it (another existing variable address or a dynamic allocated memory space address)
1st Mar 2021, 4:16 AM
visph
visph - avatar
+ 1
thanks👍🙏
1st Mar 2021, 4:17 AM
Aminu Abdulkadir
Aminu Abdulkadir - avatar
+ 1
main() { int *p; }
1st Mar 2021, 1:57 PM
ram roop Passionate to Learn Coding
ram roop Passionate to Learn Coding - avatar