Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Assign integer value to pointer?

int main(){
    int variable;
    int *ptr = &variable;
    *ptr = 20;
    printf("%d", *ptr);
    return 0;
}
Comment

assign value to a pointer

int main(){
  int arr[2];
  int* ptr = arr;
  // to assign value to a pointer we can use two methods :
  
  // Pointer Subscript Notation
  ptr[0] = 1337;								// the first element
  
  // Pointer Offset Notation
  *(ptr + 1) = 1338;							// the second element
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: enum in c++ 
Cpp :: Maximum element in a map c++ 
Cpp :: c++ pointers 
Cpp :: files c++ 
Cpp :: c++ function overloading 
Cpp :: use declaration to define a variable 
Cpp :: convert uppercase to lowercase 
Cpp :: floyd algorithm 
Cpp :: c++ visual studio 
Cpp :: problem category codechef solution in c++ 
Cpp :: ue4 endoverlap c++ 
Cpp :: Numbers Histogram in c++ 
Cpp :: progress indicator raytracer 
Cpp :: store arbitrarly large vector of doubles c++ 
Cpp :: creating large maps cpp 
Cpp :: use ster when declaring variables cpp 
Cpp :: 3. The method indexOf, part of the List interface, returns the index of the first occurrence of an object in a List. What does the following code fragment do? 
Cpp :: c++ copy vector 
Cpp :: C++ Modified Data Types List 
Cpp :: argsort c++ 
Cpp :: c++ if 
Cpp :: I/O Redirection in C++ 
Cpp :: ue4 c++ enum variable declaration 
Cpp :: cpp pointer to two dimensional array 
Cpp :: how to modify set C++ 
Cpp :: max of 3 numbers in c++ 
Cpp :: segment tree lazy propogation 
Cpp :: C++ Creating a Class Template Object 
Cpp :: Passing a string to a function 
Cpp :: print the elements of the array without using the [] notation in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =