1. Not finding help here? Sign up for a free 30min 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 programme ?

  1. Jun 2, 2009 #1
    C programme ???

    1. The problem statement, all variables and given/known data
    /* Program-8.4 */
    #include <stdio.h>
    int main()
    {
    int marks[5]= {89, 45, 73, 98, 39};
    printf("%d\n", marks); //memory addres pointed by pointer
    printf("%d\n", &marks[0]); //memory address of 1st element
    printf("%d\n", *marks); //value pointed by pointer
    printf("%d\n", marks[0]); //value of 1st array element
    return 0;


    i cant run these source code >it give an error saying
    laka.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’
    laka.c:7: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’
    line 6 and 7 refers to the lines where marks and & marks[0] are present .
    please point out the error >great help !!!!!!!



    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Jun 2, 2009 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Re: C programme ???

    The compiler is correct, format ‘%d’ DOES expects type ‘int’, but argument 2 has type ‘int *’
    You can either use '%p' or cast the address to an int, some older compilers did allow you to treat an address as an int but it causes problems with 64bit and isn't really allowed.
     
  4. Jun 2, 2009 #3
    Re: C programme ???

    thanks u so much mgb_phys .It was a great help .this programme is in my text book .So i was amazed as it didn't compile .But now i understand as it was written sometime ago ,those days compilers had allowed to do that .
     
  5. Jun 10, 2009 #4

    Mark44

    Staff: Mentor

    Re: C programme ???

    And keep in mind that the compiler issued warnings, which are not as serious as errors.
     
  6. Jun 10, 2009 #5

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Re: C programme ???

    I believe the correct format string for this is %p.

    That's arguable. Warnings are quite often more serious than errors: if you made a mistake and get an error, you can't compile your program; however if you made a mistake and ignore the warning, your buggy code actually gets executed.
     
  7. Jun 11, 2009 #6

    Mark44

    Staff: Mentor

    Re: C programme ???

    I agree in general about the warnings vs. errors, but there are different categories of warnings, some of which can be safely ignored and some of which can't. At least with a warning, you get compiled code that can produce output for further analysis and debugging.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C programme ?
  1. C\C++ help needed (Replies: 2)

  2. C++ . (Replies: 19)

Loading...