Yes, you can initialize pointers to a value on declaration, however you can’t do:
int *p = &(1000);
& is the address of operator and you can’t apply that to a constant (although if you could, that would be interesting). Try using another variable:
int foo = 1000; int *p = &foo;
or type-casting:
int *p = (int *)(1000); // or reinterpret_cast<>/static_cast<>/etc
Related Posts:
- What are the differences between a pointer variable and a reference variable in C++?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- Return array in a function
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- What is a char*?
- What exactly is nullptr?
- How to fix a “invalid operands to binary expression” error?
- What is a dangling pointer?
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- C++ – No matching member function for call to ‘push_back’
- What is uintptr_t data type
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- Pointer to incomplete class type is not allowed
- Passing a 2D array to a C++ function
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- How to access the contents of a vector from a pointer to the vector in C++?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- What does int & mean
- C++: Expression must have a constant value when declaring array inside function
- Sorting Linked List C++ with pointers
- Delete 2D array C++
- Is the sizeof(some pointer) always equal to four?
- C++ Expression must have pointer-to-object type
- C++ strings and pointers
- initial value of reference to non-const must be an lvalue
- Typedef function pointer?
- How to initialize a vector of pointers
- What is the use of intptr_t?
- how to initialize an empty integer array in c++
- C++ – Assigning null to a std::string
- C++ – Too Many Initializers for Arrays
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Reference to non-static member function must be called
- Why use pointers?
- What’s the difference between * and & in C?
- C++ pass an array by reference
- Function stoi not declared
- C++ Array of pointers: delete or delete []?
- Why should I use a pointer rather than the object itself?
- too many initializers for ‘int [0]’ c++
- Function stoi not declared
- Getting a bunch of crosses initialization error
- C++ correct way to return pointer to array from function
- Warning: comparison of distinct pointer types
- Difference between function arguments declared with & and * in C++
- Is C++ Array passed by reference or by pointer?
- Difference between the int * i and int** i
- set head to NULL (‘NULL’ : undeclared identifier)
- What is a `char*`?
- clearing a vector of pointers [duplicate]
- C++ Swapping Pointers
- Array of Linked Lists C++
- Differences between unique_ptr and shared_ptr
- C++ float array initialization
- g++ ld: symbol(s) not found for architecture x86_64
- Making my own toString() method on c++ struct
- Struct Constructor in C++?
- What is meant with “const” at end of function declaration? [duplicate]
- error: lvalue required as unary & operand
- What is use of c_str function In c++
- Is there a decent wait function in C++?
- What does T&& (double ampersand) mean in C++11?
- Reverse Contents in Array
- Why would we call cin.clear() and cin.ignore() after reading input?
- Should I learn C before learning C++?
- Comparison with string literal results in unspecified behaviour?
- c++: No instance of overloaded function
- C++ error: Undefined symbols for architecture x86_64
- Visual Studio debugger error: Unable to start program Specified file cannot be found
- Printing the correct number of decimal points with cout
- Insert object at index of vector c++
- Read whole ASCII file into C++ std::string
- Reading getline from cin into a stringstream (C++)
- C++ int float casting
- QltAW.png
- std::wstring VS std::string
- Show two digits after decimal point in c++
- gcc: undefined reference to
- “Field has incomplete type” error
- C++ Returning reference to local variable
- How do I flush the cin buffer?
- C++ Return value, reference, const reference
- C++ Global variable declaration
- OpenMP set_num_threads() is not working
- What is a null-terminated string?
- Right Justifying output stream in C++
- Serial Port (RS -232) Connection in C++
- how to destroy an object in C++
- convert string to size_t
- Multiple inputs on one line
- Getting the error floating point exception: 8