Thread: Initializing global variable in Main Method

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    11

    Initializing global variable in Main Method

    Hello everyone I want to initialize a global variable in c in my Main Function.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    // Global Variables
    struct Values* values__;
    struct FluxCapacitor** capacitors;
    
    
    
    
    struct Values {
    
    double speed_in_kmh;
    double current_power_level_in_mega_watts;
    
    };
    
    struct IndexContainer {
    
    unsigned int* cap_indicies;
    unsigned int array_length;
    
    };
    
    int main()
    {
    
    }
    I think I need to create a new instance of the structs for doing this right?
    Last edited by Jimmy589; 04-12-2017 at 01:36 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yes, that's right.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-25-2016, 05:34 AM
  2. string declaration as global vs a main local variable...
    By Jim Iwannou in forum C Programming
    Replies: 4
    Last Post: 11-14-2013, 03:12 AM
  3. how to scanf a global variable outside the main ?
    By Islam Assi in forum C Programming
    Replies: 3
    Last Post: 09-07-2013, 04:45 AM
  4. Static global variable acting as global variable?
    By Visu in forum C Programming
    Replies: 2
    Last Post: 07-20-2004, 08:46 AM
  5. How to declare a global variable in Main()
    By vnrabbit in forum C Programming
    Replies: 2
    Last Post: 06-20-2002, 12:59 PM

Tags for this Thread