Thread: what is a referencing to?

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    1

    Question what is a referencing to?

    Code:
    
    #include <stdio.h>
    
    int main(void) {
      int *a;
      {
        int b = 5;
        a = &b;
      }
      return 0;
    }
    


    since b goes out of scope, would a be referencing to garbage?

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Yes, assuming the compiler doesn't optimize everything away.
    Last edited by hamster_nz; 11-10-2020 at 02:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Referencing in C
    By joe232 in forum C Programming
    Replies: 4
    Last Post: 01-21-2019, 12:27 PM
  2. Referencing and De-referencing Question
    By audinue in forum C Programming
    Replies: 6
    Last Post: 05-15-2009, 08:22 AM
  3. Self Referencing (in a way)
    By studiesrule in forum C++ Programming
    Replies: 15
    Last Post: 10-30-2006, 04:18 AM
  4. STL list and referencing
    By gautamn in forum C++ Programming
    Replies: 1
    Last Post: 06-13-2005, 12:40 AM
  5. Help with referencing
    By daisy244 in forum C++ Programming
    Replies: 36
    Last Post: 07-29-2004, 11:57 AM

Tags for this Thread