Pointers in C / C++ [Full Course]
Why Stack Overflow recommends it
Stack Overflow users link it as a thorough pointer tutorial, both to answer beginner questions about pointer syntax and function pointers and as the source of confusing examples they ask about.
Recommended by 3 people across 3 different months, 2021 to 2023.
What it is
A 3 hour 47 minute freeCodeCamp course by Harsha and Animesh of MyCodeSchool that explains pointers in C and C++. It walks through pointer basics, arithmetic, pointers to pointers, arrays, dynamic memory with malloc and free, and function pointers, using diagrams of memory.
What people said
Strong rec Rajat Prakash · 2023-12 · Stack Overflow · on “Pointers in C: why is the * needed in *address_of_x = &x when getting the address of x?”
Read it as - int x = 4; int* address_of_x = &x; You Created a variable x of type int and stored a value 4 in it. You created a variable address_of_x of type int* i.e. pointer to an int value, and stored address of x in it. Note : Pointer is not just an address, its an address which points to some variable of type pointerType. pointerType* pointer = &variable You can go through [this video] , the best tutorial on pointers in universe :)
Recommends Bogus Bogus · 2021-07 · Stack Overflow · on “Calling printf() by its pointer”
on windows 7, compiler: mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0 int main() { int c = 5; int (*pr)(const char *const _Format, ...); pr = &printf; (*pr)("%d\n", c); return 0; } compiles and runs. you can follow the instructions in this video Pointers in C / C++ [Full Course] [this video] to get a better understanding. Around the 3 hour mark, the instructor starts talking about function pointers.
Recommends Javier · 2023-02 · Stack Overflow · on “Function pointers and callbacks in c/c++”
I was trying to remind how pointers worked in c and c++ and I found this very interesting video ( Pointers in C/C++ [this video] ). In minute 3:14:00, he begins to talk about pointer functions and callbacks, and I ended a bit confused about the real application of them. The example case he provides consists of a sorting algorithm that takes a function pointer as argument, which defines the comparison "rule" to follow (order from geater to smaller, order from smaller to greater, from greater to smaller given the absolute values...). He eventually ends with something like this: #include<stdio.h> int compare(int a, int b){ if(a > b) return -1; return 1; } void MyBubbleSort(int A[], int n, int (*comp
Cites Lukas Petrikas · 2021-04 · Stack Overflow · on “Pointers to arrays and 2 dimensional arrays”
I am learning about pointers and how they work in general. I have found some example code online: [LINK] #include<stdio.h> int main() { int *p; // pointer to int int (*parr)[5]; // pointer to an array of 5 integers int my_arr[5]; // an array of 5 integers p = my_arr; parr = my_arr; printf("Address of p = %u\n", p ); printf("Address of parr = %u\n", parr ); p++; parr++; printf("\nAfter incrementing p and parr by 1 \n\n"); printf("Address of p = %u\n", p ); printf("Address of parr = %u\n", parr ); printf("Address of parr = %u\n", *parr ); // signal to operating system program ran fine return 0; } However, I am having an error when debugging this code: Severity Code Description Project File Lin
Cites David · 2021-09 · Stack Overflow · on “Why can't I use %d to print the address of a variable”
#include <stdio.h> int main() { int a = 10; printf("address = %d\n ", &a); return 0; } test.c:11:29: warning: format specifies type 'int' but the argument has type 'int *' [-Wformat] printf("address = %d\n ", &a); output if I use %d address = -376933160 output if I use %p , this is also weird, I think I should get a positive integer instead of this? address = 0x7ffee07004d8 I know the correct way to do this should be %p, but I see in YouTube video, people can just use %d and don't get any problems. I wonder if my setting is wrong, I am using VS code to run the program. video example [this video] Update Now I am aware -376933160 is an incorrect value, but still I wonder why it just outputs a rando
Cites mnj · 2021-12 · Stack Overflow · on “Multi-dimensional array as a pointer - where are addresses of subarrays stored?”
In the tutorial video about pointers ( [this video] ) there are the following code and illustration: int B[2][3]; // we define an array [LINK] The following facts about that code were given: Printing B (or &B[0]) would return 400 (the address of the first sub-array) Printing *B (or B[0] or &B[0][0]) would return 400 (the address of the first element in the first sub-array) I struggle a bit with an understanding of that. How can B and *B have the same value? We can clearly see in the illustration that under address 400 there is a value 2. If B = 400, then *B = 2! My understanding is that the value of B would be the address of the first element of the outer array in the memory. Then, the *B would r
Cites Honza Píka · 2022-09 · Stack Overflow · on “How many elements does the compiler take from an array which is function argument?”
@WeatherVane thank u. i understand the difference. but the problem was that in tutorial the exact same code was returning 4 and 4 and that got me confused. xd (link if u want: [this video] time: 1:15:31)
Cites Honza Píka · 2022-09 · Stack Overflow · on “How many elements does the compiler take from an array which is function argument?”
thx a lot, i was asking because i saw this in one tutorial and he was using the exact same code, but unlike me he was getting 4 and 4. That got me confused (link: [this video] time 1:15:31)