C++ pointers explained easy 👈

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 55

  • @BroCodez
    @BroCodez  2 года назад +29

    #include
    int main() {
    // pointers = variable that stores a memory address of another variable
    // sometimes it's easier to work with an address
    // & address-of operator
    // * dereference operator
    std::string name = "Bro";
    int age = 21;
    std::string freePizzas[5] = {"pizza1", "pizza2", "pizza3", "pizza4", "pizza5"};

    std::string *pName = &name;
    int *pAge = &age;
    std::string *pFreePizzas = freePizzas;
    std::cout

  • @tarsow7741
    @tarsow7741 4 месяца назад +59

    if its not clear to everyone, arrays are just pointers, which point to the first element in the list, for example: arr[i] is the same as *(arr + i), its also one of the reasons you can write i[arr] in C++ and it will give the same output as arr[i], there is also other things that are possible with arrays/pointers:
    #include
    int main(int argc, char *argv[])
    {
    int size = 3;
    int array[size] = {10, 5, 3, 1, -2, -4, -7};
    std::cout

  • @Pranav-nx4cm
    @Pranav-nx4cm Месяц назад +52

    int diddy = 1000;
    int *pDiddy = &diddy;

    • @danji3376
      @danji3376 Месяц назад +2

      address of operator: pDiddy Party

  • @wlsedlacek
    @wlsedlacek Год назад +7

    int pointer = 100;
    int *pPointer = &pointer

  • @shreedhoni4522
    @shreedhoni4522 2 года назад +13

    If I want to locate the pizza3 in the array ,how should I use my pointer?

    • @game-op8up
      @game-op8up 2 года назад +27

      Instead of this:
      std::cout

    • @dazai826
      @dazai826 5 месяцев назад +2

      @@game-op8up yeah, thats why you use int pointers not string pointers. infact myarray[index] is defined in C/C++ to be equivalent to *(myarray + index), thats why while accessing first element by using myarray[0], like in the video, is equivalent to *(myarray + 0) = *(myarray) = *myarray.

    • @elchapo2299
      @elchapo2299 2 месяца назад

      std::string freePizzas[] = {"pizza1", "pizza2", "pizza3", "pizza4", "pizza5"};
      std::string* pFreePizzas = freePizzas;
      std::cout

  • @abdullahsaid-lh1hv
    @abdullahsaid-lh1hv 4 месяца назад +3

    bro you are so amazing you solved my biggest problem
    of pointers love U😘😘😘😘😘😘😘😘

  • @Leon-r7w
    @Leon-r7w 4 месяца назад +7

    Bro has the best videos ngel. W bro❤❤👍

  • @animationaryz
    @animationaryz 6 дней назад +1

    Why it didn't give the error in
    string *pname =&name;
    int *pAge =&age;
    But gives the error in
    string *freepizzas =&freepizzas
    Why can't we use "&" in this but can use in those above

    • @ahmed7aleem943
      @ahmed7aleem943 5 дней назад

      Look let's imagine that the int and string are taking 1 space in memory so when I want to get them I call the address of this space but in array you have 5 spaces each one is separated just they are in like a container named array and this array addressed by the first value so when you want to point a pointer on array you cannot make a pointer point to all those spaces
      hope you got it

    • @animationaryz
      @animationaryz 3 дня назад

      ​ Not really but it was a little bit helpful. Thank you brother 🙋🏻‍♂️​@@ahmed7aleem943

  • @HunaBopa
    @HunaBopa Год назад +3

    assignment: #include
    int main()
    {
    double gpa[] = {2.5, 3.3, 4.3, 5.0, 4.05};
    double *pGPA = gpa;
    for (int i = 0; i < 5; i ++)
    {
    std::cout

  • @tavares._art
    @tavares._art 10 месяцев назад +8

    int main{
    std:: string = Bruh;
    std:: string = *pBruh = &Bruh;
    std::cout

  • @ZXR4GRZ
    @ZXR4GRZ 2 месяца назад +3

    Thank you!❤

  • @Mellows.
    @Mellows. 4 месяца назад

    why does the output to your freepizzas array and the pointer to said array differs when arrays are already pointers?
    i tried it myself and for me it outputs the same thing

  • @AjkRL
    @AjkRL 16 дней назад

    float pointy = 0.34;
    float *pPointy = &pointy;
    cout

  • @MooseShower
    @MooseShower 4 месяца назад

    Thank you! It looks like I just kept forgetting the & which is why my code never worked for my homework

  • @grimquokka9843
    @grimquokka9843 5 месяцев назад +43

    why don't you use namespace std : (

    • @Pascal-1
      @Pascal-1 4 месяца назад +19

      I'm watching the 6 hours c++ tutorial he made, and there he says that he doesn't like doing that

    • @Cinarbayramic
      @Cinarbayramic 3 месяца назад +25

      I think it was considered bad practice cuz other libraries might have functions with the same name

    • @StampleD2147AI
      @StampleD2147AI 3 месяца назад +24

      It's because it increases the chance for a namespace collision.

    • @HiboMoh
      @HiboMoh 3 месяца назад +2

      He already use :: std if u use (::std) you don’t need using namespace std:

    • @baconheadhair6938
      @baconheadhair6938 Месяц назад

      @@HiboMohits an ease of use thing not a need thing. if you put use namespace std or define std functions u can just say string instead of std::string

  • @bebe9143
    @bebe9143 18 дней назад

    gbu

  • @Yousif_Maksabo
    @Yousif_Maksabo 4 месяца назад +3

    #include
    int main() {
    double temp = 44.2;
    double *pTemp = &temp;
    std::cout

  • @code-charm-linux
    @code-charm-linux 5 месяцев назад

    #include
    int main()
    {
    char grades[5] = {'A', 'B', 'C', 'D', 'F'};
    char *pGrades = grades;
    std::cout

  • @IslamMazen-xs3rh
    @IslamMazen-xs3rh 3 месяца назад +4

    free pizza is crazy

    • @NotLiamH
      @NotLiamH Месяц назад +2

      Yeah, where is this memory address with all this free pizza?

    • @baconheadhair6938
      @baconheadhair6938 Месяц назад

      @@NotLiamHpizza

  • @znedj
    @znedj Месяц назад

    Thanks.

  • @zakmartin7567
    @zakmartin7567 2 года назад

    yesssss. keep the updates flowing :3

  • @timwiller3103
    @timwiller3103 День назад

    now i want a free pizza

  • @HunaBopa
    @HunaBopa Год назад +3

    Bro, why don't you show yourself on your video tutorials ? I think it would be more interactive for your pupils or fans to engage learning.

    • @jerryjerryjerry1
      @jerryjerryjerry1 Год назад

      because he is evil

    • @tavares._art
      @tavares._art 10 месяцев назад

      hes dream

    • @HunaBopa
      @HunaBopa 10 месяцев назад +4

      @@jerryjerryjerry1 How do you know that? Bro Code dedicates his time to create quality content for his viewers. His video tutorials are great yet he doesn't show up himself. His videos has helped me a lot. I think Bro Code is a good person.

    • @jerryjerryjerry1
      @jerryjerryjerry1 10 месяцев назад

      i think you should suck it dude
      @@HunaBopa

    • @cursory9031
      @cursory9031 6 месяцев назад +4

      It’s better not to show his face

  • @dghuvcg4924
    @dghuvcg4924 Месяц назад

    int pizza =15;
    int *pPizza=&pizza;
    cout

  • @TomášHulina
    @TomášHulina Месяц назад

    int main() {
    std::string name = "Marcus";
    std::string *pName = &name;
    std::cout

  • @heavyymetal
    @heavyymetal Год назад +3

    int main(){
    string favouriteGames[5] = {"Overwatch 1", "Terraria", "Rocket League", "Minecraft", "Overwatch 2"};
    string *pFavouriteGames = favouriteGames;
    cout

    • @zinebell3225
      @zinebell3225 Год назад +1

      why arrays are already addresses?

    • @SauravKumar-lq6hr
      @SauravKumar-lq6hr 10 месяцев назад

      @@zinebell3225 because the array's name itself
      represents the address of its first element.

    • @imanalien4129
      @imanalien4129 2 месяца назад

      @@SauravKumar-lq6hr how to access the exact game in the array list? for example Overwatch 2?