Thread: understanding this code

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    24

    understanding this code

    [code]
    strcpy(current_planet.name, "Jupiter");
    current_planet.diameter = 142800;
    current_planet.moons = 16;
    current_planet.orbit_time = 11.9;
    current_planet.rotation_time = 9.925;



    printf("%s's equatorial diameter is %.1f km.\n",


    current_planet.name, current_planet.diameter);
    [\code]

    If I am understanding this correctly, the output would be:
    Jupiter's equatorial diameter is 142800.0 km.
    Last edited by bellagomes21; 02-29-2016 at 04:17 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
    So what is stopping you from typing the code into a complete program, compiling it and seeing for yourself?
    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.

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    112
    That should be the output, but who knows without a full program. Is this an exercise in understanding structs?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help understanding this code
    By jim_0 in forum C++ Programming
    Replies: 1
    Last Post: 11-27-2013, 08:45 AM
  2. Need help understanding this code
    By sameertelkar in forum C Programming
    Replies: 11
    Last Post: 01-04-2013, 07:36 AM
  3. Need Help in Understanding this Code
    By Linked_List in forum C Programming
    Replies: 3
    Last Post: 09-04-2012, 09:32 PM
  4. code understanding
    By elwad in forum C Programming
    Replies: 5
    Last Post: 04-18-2009, 06:57 AM
  5. Help understanding a code
    By lolguy in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-15-2009, 04:13 PM

Tags for this Thread