1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C programming problem

  1. Dec 1, 2009 #1
    1. The problem statement, all variables and given/known data
    Write a C program to use a function to add two 16bit and two 32bit integers together and return a long integer result.
    Call the function twice with different parameters and print the results.
    Declare your input variables to one of the function calls as local variables (on the stack) and the other as global variables

    2. Relevant equations



    3. The attempt at a solution
    Ok so my first problem is the interpretation of the question. Should I add two 16bit numbers, then add the two 32bit numbers, or do I add them all together? Its a little bit confusing.

    Calling the function twice would be no problem for me, if I was to declare the variables locally they could be input when the function is called. Or if i was to declare the variables globally then I could just add the variables by referencing their name in the function. But it is doing both of these things with one function that has left me stuck. Anybody any ideas or starting points? Thank you in advance
     
  2. jcsd
  3. Dec 1, 2009 #2

    Mark44

    Staff: Mentor

    My interpretation is that you add all four numbers together in a function that has four parameters. I would advise against just using the global variables inside the function without passing them in as parameters. Even though you could refer to them inside the function without passing them in through the parameter list, it is not a good design practice to do so.
    If this is a problem that your instructor created, you should consider asking him/her for some clarification.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C programming problem
  1. Problem in C program ? (Replies: 3)

  2. Base C program problem (Replies: 5)

Loading...