Search Results
7/26/2025, 3:52:49 AM
7/8/2025, 5:31:46 AM
6/21/2025, 4:09:24 AM
>>528222976
Think of it: why would you even use pointers in the first place?
Example:
int a = 1;
int b = a;
That just works and there's nothing wrong with it. It's also fast because it just copies 32 or 64-bits depending on compiler optimization, CPU architecture and more.
Example 2:
int f(int a)
{
// There is NO way to change something outside this function without resorting to making the variable you want to change into a global or returning the new value from this function.
}
f(a);
int f2(int *a)
{
*a = 1; // Pointers are required in this case because there is no other way aside from the options I mentioned in f(int a)
}
int fret(int a)
{
return 1; // If you're not using global variables then you would return the new value. For this case this would still be fast and the compiler will insert not too many instructions.
}
int b = fret(a);
Example 3:
struct Data {
int myData[2000];
};
int f(Data d) // This will copy an int array every time you call this function if it even works at all because you might need more stack space.
{
// ...
}
Data f(void) // This will return and also copy an entire int array.
{
// ...
}
Depending on how the compiler will optimize this it may do a variety of options like adding a implicit pointer in the instructions before you call f(). But there are no guarantees and the worst case is that it will copy data unnecessarily.
Example 4:
int f(int *myData)
{
// ...
}
f(d.myData); // Passing a member will convert the array to a pointer.
Example 5:
int myData[5] = {1,2,3,4,5};
int *myPtr = myData;
0[myPtr] == myPtr[0] // Arrays are pointers so this will both result in *(myPtr + 0) or *(0 + myPtr)
Think of it: why would you even use pointers in the first place?
Example:
int a = 1;
int b = a;
That just works and there's nothing wrong with it. It's also fast because it just copies 32 or 64-bits depending on compiler optimization, CPU architecture and more.
Example 2:
int f(int a)
{
// There is NO way to change something outside this function without resorting to making the variable you want to change into a global or returning the new value from this function.
}
f(a);
int f2(int *a)
{
*a = 1; // Pointers are required in this case because there is no other way aside from the options I mentioned in f(int a)
}
int fret(int a)
{
return 1; // If you're not using global variables then you would return the new value. For this case this would still be fast and the compiler will insert not too many instructions.
}
int b = fret(a);
Example 3:
struct Data {
int myData[2000];
};
int f(Data d) // This will copy an int array every time you call this function if it even works at all because you might need more stack space.
{
// ...
}
Data f(void) // This will return and also copy an entire int array.
{
// ...
}
Depending on how the compiler will optimize this it may do a variety of options like adding a implicit pointer in the instructions before you call f(). But there are no guarantees and the worst case is that it will copy data unnecessarily.
Example 4:
int f(int *myData)
{
// ...
}
f(d.myData); // Passing a member will convert the array to a pointer.
Example 5:
int myData[5] = {1,2,3,4,5};
int *myPtr = myData;
0[myPtr] == myPtr[0] // Arrays are pointers so this will both result in *(myPtr + 0) or *(0 + myPtr)
6/20/2025, 6:02:02 PM
Page 1