Format specifies type “int*” but argument has type “int”What is the argument for printf that formats a long?What is the difference between const int*, const int * const, and int const *?Improve INSERT-per-second performance of SQLite?convert int to float to hexCorrect format specifier for double in printfTrouble with input using scanf()Format specifier for unsigned charData structure and patients recordsC Printfs are expecting a Type Specifiergetting values for an array using scanf function in C

Project Euler problem #112

Two men on a road

How do draw effects during the discard phase work?

Problem with listing a directory to grep

Complex conjugate and transpose "with respect to a basis"

Supervisor wants me to support a diploma-thesis SW tool after I graduated

If every star in the universe except the Sun were destroyed, would we die?

What is the purpose of the rotating plate in front of the lock?

Why are there no wireless switches?

Dragons and gems

The Green Glass Door, Revisited

Relationship between speed and cadence?

Contour plot of a sequence of spheres with increasing radius

How can I hint that my character isn't real?

Is this ram compatible with iMac 27"?

Do you need to burn fuel between gravity assists?

How to improvise or make pot grip / pot handle

Short story: Interstellar inspector senses "off" nature of planet hiding aggressive culture

What's the biggest difference between these two photos?

I multiply the source, you (probably) multiply the output!

Entering the US with dual citizenship but US passport is long expired?

Project Euler Problem 45

Examples where "thin + thin = nice and thick"

Why is Western European music harmonically driven?



Format specifies type “int*” but argument has type “int”


What is the argument for printf that formats a long?What is the difference between const int*, const int * const, and int const *?Improve INSERT-per-second performance of SQLite?convert int to float to hexCorrect format specifier for double in printfTrouble with input using scanf()Format specifier for unsigned charData structure and patients recordsC Printfs are expecting a Type Specifiergetting values for an array using scanf function in C






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















Creating a code that prints out Body Mass Index



printf("What is your height in inches?n");
scanf("%d", height);

printf("What is your weight in pounds?n");
scanf("%d", weight);


I have height and weight as initialized as int height, int weight, but the program is not letting me run it because it says the format is type int* on both scanf lines. What am I doing wrong to get this program to run?










share|improve this question





















  • 1





    Note: Good code checks the return value from scanf().

    – chux
    Aug 29 '14 at 19:49






  • 1





    @chux good code doesn't use scanf() to read user input.

    – The Paramagnetic Croissant
    Aug 30 '14 at 5:33






  • 1





    @The Paramagnetic Croissant Mostly agree and more. IMO good code checks scanf(), better code uses fgets() and checks/parses that result instead. Robust code uses fgets() with all that and also handles file IO errors. All steps may be much for OP, so promoted the first.

    – chux
    Aug 30 '14 at 17:12






  • 1





    @chux "Robust code uses fgets()" - exactly.

    – The Paramagnetic Croissant
    Aug 30 '14 at 17:18











  • @TheParamagneticCroissant, I am sorry but scanf is good enough for scanning integers if you check the return value.

    – Ajay Brahmakshatriya
    Jun 15 '17 at 3:05

















2















Creating a code that prints out Body Mass Index



printf("What is your height in inches?n");
scanf("%d", height);

printf("What is your weight in pounds?n");
scanf("%d", weight);


I have height and weight as initialized as int height, int weight, but the program is not letting me run it because it says the format is type int* on both scanf lines. What am I doing wrong to get this program to run?










share|improve this question





















  • 1





    Note: Good code checks the return value from scanf().

    – chux
    Aug 29 '14 at 19:49






  • 1





    @chux good code doesn't use scanf() to read user input.

    – The Paramagnetic Croissant
    Aug 30 '14 at 5:33






  • 1





    @The Paramagnetic Croissant Mostly agree and more. IMO good code checks scanf(), better code uses fgets() and checks/parses that result instead. Robust code uses fgets() with all that and also handles file IO errors. All steps may be much for OP, so promoted the first.

    – chux
    Aug 30 '14 at 17:12






  • 1





    @chux "Robust code uses fgets()" - exactly.

    – The Paramagnetic Croissant
    Aug 30 '14 at 17:18











  • @TheParamagneticCroissant, I am sorry but scanf is good enough for scanning integers if you check the return value.

    – Ajay Brahmakshatriya
    Jun 15 '17 at 3:05













2












2








2


3






Creating a code that prints out Body Mass Index



printf("What is your height in inches?n");
scanf("%d", height);

printf("What is your weight in pounds?n");
scanf("%d", weight);


I have height and weight as initialized as int height, int weight, but the program is not letting me run it because it says the format is type int* on both scanf lines. What am I doing wrong to get this program to run?










share|improve this question
















Creating a code that prints out Body Mass Index



printf("What is your height in inches?n");
scanf("%d", height);

printf("What is your weight in pounds?n");
scanf("%d", weight);


I have height and weight as initialized as int height, int weight, but the program is not letting me run it because it says the format is type int* on both scanf lines. What am I doing wrong to get this program to run?







c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 29 '14 at 19:56









user1336087

4,2057 gold badges30 silver badges37 bronze badges




4,2057 gold badges30 silver badges37 bronze badges










asked Aug 29 '14 at 19:27









Josh FairJosh Fair

261 gold badge1 silver badge2 bronze badges




261 gold badge1 silver badge2 bronze badges










  • 1





    Note: Good code checks the return value from scanf().

    – chux
    Aug 29 '14 at 19:49






  • 1





    @chux good code doesn't use scanf() to read user input.

    – The Paramagnetic Croissant
    Aug 30 '14 at 5:33






  • 1





    @The Paramagnetic Croissant Mostly agree and more. IMO good code checks scanf(), better code uses fgets() and checks/parses that result instead. Robust code uses fgets() with all that and also handles file IO errors. All steps may be much for OP, so promoted the first.

    – chux
    Aug 30 '14 at 17:12






  • 1





    @chux "Robust code uses fgets()" - exactly.

    – The Paramagnetic Croissant
    Aug 30 '14 at 17:18











  • @TheParamagneticCroissant, I am sorry but scanf is good enough for scanning integers if you check the return value.

    – Ajay Brahmakshatriya
    Jun 15 '17 at 3:05












  • 1





    Note: Good code checks the return value from scanf().

    – chux
    Aug 29 '14 at 19:49






  • 1





    @chux good code doesn't use scanf() to read user input.

    – The Paramagnetic Croissant
    Aug 30 '14 at 5:33






  • 1





    @The Paramagnetic Croissant Mostly agree and more. IMO good code checks scanf(), better code uses fgets() and checks/parses that result instead. Robust code uses fgets() with all that and also handles file IO errors. All steps may be much for OP, so promoted the first.

    – chux
    Aug 30 '14 at 17:12






  • 1





    @chux "Robust code uses fgets()" - exactly.

    – The Paramagnetic Croissant
    Aug 30 '14 at 17:18











  • @TheParamagneticCroissant, I am sorry but scanf is good enough for scanning integers if you check the return value.

    – Ajay Brahmakshatriya
    Jun 15 '17 at 3:05







1




1





Note: Good code checks the return value from scanf().

– chux
Aug 29 '14 at 19:49





Note: Good code checks the return value from scanf().

– chux
Aug 29 '14 at 19:49




1




1





@chux good code doesn't use scanf() to read user input.

– The Paramagnetic Croissant
Aug 30 '14 at 5:33





@chux good code doesn't use scanf() to read user input.

– The Paramagnetic Croissant
Aug 30 '14 at 5:33




1




1





@The Paramagnetic Croissant Mostly agree and more. IMO good code checks scanf(), better code uses fgets() and checks/parses that result instead. Robust code uses fgets() with all that and also handles file IO errors. All steps may be much for OP, so promoted the first.

– chux
Aug 30 '14 at 17:12





@The Paramagnetic Croissant Mostly agree and more. IMO good code checks scanf(), better code uses fgets() and checks/parses that result instead. Robust code uses fgets() with all that and also handles file IO errors. All steps may be much for OP, so promoted the first.

– chux
Aug 30 '14 at 17:12




1




1





@chux "Robust code uses fgets()" - exactly.

– The Paramagnetic Croissant
Aug 30 '14 at 17:18





@chux "Robust code uses fgets()" - exactly.

– The Paramagnetic Croissant
Aug 30 '14 at 17:18













@TheParamagneticCroissant, I am sorry but scanf is good enough for scanning integers if you check the return value.

– Ajay Brahmakshatriya
Jun 15 '17 at 3:05





@TheParamagneticCroissant, I am sorry but scanf is good enough for scanning integers if you check the return value.

– Ajay Brahmakshatriya
Jun 15 '17 at 3:05












4 Answers
4






active

oldest

votes


















9
















scanf requires the format (your "%d") and also a memory address of the variable where it should put the value that was read. height and weight are int, not the memory address of an int (this is what int * type 'says': a pointer to a memory address of an int). You should use the operator & to pass the memory address to scanf.



Your code should be:



printf("What is your height in inches?n");
scanf("%d", &height);

printf("What is your weight in pounds?n");
scanf("%d", &weight);


Update: As The Paramagnetic Croissant pointed out, reference is not the correct term.So I changed it to memory address.






share|improve this answer






















  • 1





    What "references"? There ain't no references in C. Those are pointers.

    – The Paramagnetic Croissant
    Aug 30 '14 at 5:34











  • @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

    – chux
    Aug 30 '14 at 17:19











  • @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

    – The Paramagnetic Croissant
    Aug 30 '14 at 17:20











  • Yeah, the term reference was wrong. I changed to memory address. Thanks

    – braindf
    Aug 30 '14 at 18:20


















1
















taking into account what the other users have said, try something like this;



int height; <---- declaring your variables
int weight;
float bmi; <---- bmi is a float because it has decimal values

printf("What is your height in inches?n");
scanf("%d", &height); <----- don't forget to have '&' before variable you are storing the value in

printf("What is your weight in pounds?n");
scanf("%d", &weight);


bmi = (weight / pow(height, 2)) * 703; <---- the math for calculating BMI
printf("The BMI is %fn", bmi);


(for this you will need to include the math.h library.)






share|improve this answer


































    0
















    scanf reads characters from the standard input, interprets them according to the format specifiers here "%d" for integers and stores them in corresponding arguments.



    To store them you must specify &variable_name, it will specify the address location where the input should be stored.



    Your scanf statement should be:



    //For storing value of height
    scanf(" %d", &height);
    //For storing value of weight
    scanf(" %d", &weight);





    share|improve this answer


































      0
















      Like others have said, it's because when you have a value that is a primitive (like an int) that is being read with scanf you have to pass the memory address to that primitive value. However, just to add something that has not been mentioned yet, the same is not true for strings.



      Example 1. Using with a primitive value



      #include <stdio.h>

      int main()

      int primitiveInteger; // integer (i.e. no decimals allowed)
      scanf("%i", &primitiveInteger); // notice the address of operator getting the address of the primitiveInteger variable by prepending the variable name with the & (address of) operator.
      printf("Your integer is %i", primitiveInteger); simply printing it out here to the stdout stream (most likely your terminal.)



      Example 2. Not using a primitive value



      #include <stdio.h>

      int main()

      char *nonPrimitiveString; // initialize a string variable which is NOT a primitive in C
      scanf("%s", nonPrimitiveString); // notice there is no address of operator here
      printf("%sn", nonPrimitiveString); // prints string






      share|improve this answer





























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25574981%2fformat-specifies-type-int-but-argument-has-type-int%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        9
















        scanf requires the format (your "%d") and also a memory address of the variable where it should put the value that was read. height and weight are int, not the memory address of an int (this is what int * type 'says': a pointer to a memory address of an int). You should use the operator & to pass the memory address to scanf.



        Your code should be:



        printf("What is your height in inches?n");
        scanf("%d", &height);

        printf("What is your weight in pounds?n");
        scanf("%d", &weight);


        Update: As The Paramagnetic Croissant pointed out, reference is not the correct term.So I changed it to memory address.






        share|improve this answer






















        • 1





          What "references"? There ain't no references in C. Those are pointers.

          – The Paramagnetic Croissant
          Aug 30 '14 at 5:34











        • @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

          – chux
          Aug 30 '14 at 17:19











        • @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

          – The Paramagnetic Croissant
          Aug 30 '14 at 17:20











        • Yeah, the term reference was wrong. I changed to memory address. Thanks

          – braindf
          Aug 30 '14 at 18:20















        9
















        scanf requires the format (your "%d") and also a memory address of the variable where it should put the value that was read. height and weight are int, not the memory address of an int (this is what int * type 'says': a pointer to a memory address of an int). You should use the operator & to pass the memory address to scanf.



        Your code should be:



        printf("What is your height in inches?n");
        scanf("%d", &height);

        printf("What is your weight in pounds?n");
        scanf("%d", &weight);


        Update: As The Paramagnetic Croissant pointed out, reference is not the correct term.So I changed it to memory address.






        share|improve this answer






















        • 1





          What "references"? There ain't no references in C. Those are pointers.

          – The Paramagnetic Croissant
          Aug 30 '14 at 5:34











        • @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

          – chux
          Aug 30 '14 at 17:19











        • @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

          – The Paramagnetic Croissant
          Aug 30 '14 at 17:20











        • Yeah, the term reference was wrong. I changed to memory address. Thanks

          – braindf
          Aug 30 '14 at 18:20













        9














        9










        9









        scanf requires the format (your "%d") and also a memory address of the variable where it should put the value that was read. height and weight are int, not the memory address of an int (this is what int * type 'says': a pointer to a memory address of an int). You should use the operator & to pass the memory address to scanf.



        Your code should be:



        printf("What is your height in inches?n");
        scanf("%d", &height);

        printf("What is your weight in pounds?n");
        scanf("%d", &weight);


        Update: As The Paramagnetic Croissant pointed out, reference is not the correct term.So I changed it to memory address.






        share|improve this answer















        scanf requires the format (your "%d") and also a memory address of the variable where it should put the value that was read. height and weight are int, not the memory address of an int (this is what int * type 'says': a pointer to a memory address of an int). You should use the operator & to pass the memory address to scanf.



        Your code should be:



        printf("What is your height in inches?n");
        scanf("%d", &height);

        printf("What is your weight in pounds?n");
        scanf("%d", &weight);


        Update: As The Paramagnetic Croissant pointed out, reference is not the correct term.So I changed it to memory address.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 15 '17 at 0:12









        Bruno Lange

        6908 silver badges11 bronze badges




        6908 silver badges11 bronze badges










        answered Aug 29 '14 at 19:33









        braindfbraindf

        5342 silver badges10 bronze badges




        5342 silver badges10 bronze badges










        • 1





          What "references"? There ain't no references in C. Those are pointers.

          – The Paramagnetic Croissant
          Aug 30 '14 at 5:34











        • @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

          – chux
          Aug 30 '14 at 17:19











        • @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

          – The Paramagnetic Croissant
          Aug 30 '14 at 17:20











        • Yeah, the term reference was wrong. I changed to memory address. Thanks

          – braindf
          Aug 30 '14 at 18:20












        • 1





          What "references"? There ain't no references in C. Those are pointers.

          – The Paramagnetic Croissant
          Aug 30 '14 at 5:34











        • @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

          – chux
          Aug 30 '14 at 17:19











        • @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

          – The Paramagnetic Croissant
          Aug 30 '14 at 17:20











        • Yeah, the term reference was wrong. I changed to memory address. Thanks

          – braindf
          Aug 30 '14 at 18:20







        1




        1





        What "references"? There ain't no references in C. Those are pointers.

        – The Paramagnetic Croissant
        Aug 30 '14 at 5:34





        What "references"? There ain't no references in C. Those are pointers.

        – The Paramagnetic Croissant
        Aug 30 '14 at 5:34













        @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

        – chux
        Aug 30 '14 at 17:19





        @The Paramagnetic Croissant C does have a referenced type. "A pointer type may be derived from a function type or an object type, called the referenced type" C11dr §6.2.5 20. Perhaps this answer is using reference in that context.

        – chux
        Aug 30 '14 at 17:19













        @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

        – The Paramagnetic Croissant
        Aug 30 '14 at 17:20





        @chux I know about that, but the question using it is unfortunate and incorrect, since a referenced type is not the same thing as a reference, let alone a pointer.

        – The Paramagnetic Croissant
        Aug 30 '14 at 17:20













        Yeah, the term reference was wrong. I changed to memory address. Thanks

        – braindf
        Aug 30 '14 at 18:20





        Yeah, the term reference was wrong. I changed to memory address. Thanks

        – braindf
        Aug 30 '14 at 18:20













        1
















        taking into account what the other users have said, try something like this;



        int height; <---- declaring your variables
        int weight;
        float bmi; <---- bmi is a float because it has decimal values

        printf("What is your height in inches?n");
        scanf("%d", &height); <----- don't forget to have '&' before variable you are storing the value in

        printf("What is your weight in pounds?n");
        scanf("%d", &weight);


        bmi = (weight / pow(height, 2)) * 703; <---- the math for calculating BMI
        printf("The BMI is %fn", bmi);


        (for this you will need to include the math.h library.)






        share|improve this answer































          1
















          taking into account what the other users have said, try something like this;



          int height; <---- declaring your variables
          int weight;
          float bmi; <---- bmi is a float because it has decimal values

          printf("What is your height in inches?n");
          scanf("%d", &height); <----- don't forget to have '&' before variable you are storing the value in

          printf("What is your weight in pounds?n");
          scanf("%d", &weight);


          bmi = (weight / pow(height, 2)) * 703; <---- the math for calculating BMI
          printf("The BMI is %fn", bmi);


          (for this you will need to include the math.h library.)






          share|improve this answer





























            1














            1










            1









            taking into account what the other users have said, try something like this;



            int height; <---- declaring your variables
            int weight;
            float bmi; <---- bmi is a float because it has decimal values

            printf("What is your height in inches?n");
            scanf("%d", &height); <----- don't forget to have '&' before variable you are storing the value in

            printf("What is your weight in pounds?n");
            scanf("%d", &weight);


            bmi = (weight / pow(height, 2)) * 703; <---- the math for calculating BMI
            printf("The BMI is %fn", bmi);


            (for this you will need to include the math.h library.)






            share|improve this answer















            taking into account what the other users have said, try something like this;



            int height; <---- declaring your variables
            int weight;
            float bmi; <---- bmi is a float because it has decimal values

            printf("What is your height in inches?n");
            scanf("%d", &height); <----- don't forget to have '&' before variable you are storing the value in

            printf("What is your weight in pounds?n");
            scanf("%d", &weight);


            bmi = (weight / pow(height, 2)) * 703; <---- the math for calculating BMI
            printf("The BMI is %fn", bmi);


            (for this you will need to include the math.h library.)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 30 '14 at 9:09

























            answered Aug 30 '14 at 5:19









            Xavier DassXavier Dass

            4268 silver badges17 bronze badges




            4268 silver badges17 bronze badges
























                0
















                scanf reads characters from the standard input, interprets them according to the format specifiers here "%d" for integers and stores them in corresponding arguments.



                To store them you must specify &variable_name, it will specify the address location where the input should be stored.



                Your scanf statement should be:



                //For storing value of height
                scanf(" %d", &height);
                //For storing value of weight
                scanf(" %d", &weight);





                share|improve this answer































                  0
















                  scanf reads characters from the standard input, interprets them according to the format specifiers here "%d" for integers and stores them in corresponding arguments.



                  To store them you must specify &variable_name, it will specify the address location where the input should be stored.



                  Your scanf statement should be:



                  //For storing value of height
                  scanf(" %d", &height);
                  //For storing value of weight
                  scanf(" %d", &weight);





                  share|improve this answer





























                    0














                    0










                    0









                    scanf reads characters from the standard input, interprets them according to the format specifiers here "%d" for integers and stores them in corresponding arguments.



                    To store them you must specify &variable_name, it will specify the address location where the input should be stored.



                    Your scanf statement should be:



                    //For storing value of height
                    scanf(" %d", &height);
                    //For storing value of weight
                    scanf(" %d", &weight);





                    share|improve this answer















                    scanf reads characters from the standard input, interprets them according to the format specifiers here "%d" for integers and stores them in corresponding arguments.



                    To store them you must specify &variable_name, it will specify the address location where the input should be stored.



                    Your scanf statement should be:



                    //For storing value of height
                    scanf(" %d", &height);
                    //For storing value of weight
                    scanf(" %d", &weight);






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 29 '14 at 19:57

























                    answered Aug 29 '14 at 19:46









                    user1336087user1336087

                    4,2057 gold badges30 silver badges37 bronze badges




                    4,2057 gold badges30 silver badges37 bronze badges
























                        0
















                        Like others have said, it's because when you have a value that is a primitive (like an int) that is being read with scanf you have to pass the memory address to that primitive value. However, just to add something that has not been mentioned yet, the same is not true for strings.



                        Example 1. Using with a primitive value



                        #include <stdio.h>

                        int main()

                        int primitiveInteger; // integer (i.e. no decimals allowed)
                        scanf("%i", &primitiveInteger); // notice the address of operator getting the address of the primitiveInteger variable by prepending the variable name with the & (address of) operator.
                        printf("Your integer is %i", primitiveInteger); simply printing it out here to the stdout stream (most likely your terminal.)



                        Example 2. Not using a primitive value



                        #include <stdio.h>

                        int main()

                        char *nonPrimitiveString; // initialize a string variable which is NOT a primitive in C
                        scanf("%s", nonPrimitiveString); // notice there is no address of operator here
                        printf("%sn", nonPrimitiveString); // prints string






                        share|improve this answer































                          0
















                          Like others have said, it's because when you have a value that is a primitive (like an int) that is being read with scanf you have to pass the memory address to that primitive value. However, just to add something that has not been mentioned yet, the same is not true for strings.



                          Example 1. Using with a primitive value



                          #include <stdio.h>

                          int main()

                          int primitiveInteger; // integer (i.e. no decimals allowed)
                          scanf("%i", &primitiveInteger); // notice the address of operator getting the address of the primitiveInteger variable by prepending the variable name with the & (address of) operator.
                          printf("Your integer is %i", primitiveInteger); simply printing it out here to the stdout stream (most likely your terminal.)



                          Example 2. Not using a primitive value



                          #include <stdio.h>

                          int main()

                          char *nonPrimitiveString; // initialize a string variable which is NOT a primitive in C
                          scanf("%s", nonPrimitiveString); // notice there is no address of operator here
                          printf("%sn", nonPrimitiveString); // prints string






                          share|improve this answer





























                            0














                            0










                            0









                            Like others have said, it's because when you have a value that is a primitive (like an int) that is being read with scanf you have to pass the memory address to that primitive value. However, just to add something that has not been mentioned yet, the same is not true for strings.



                            Example 1. Using with a primitive value



                            #include <stdio.h>

                            int main()

                            int primitiveInteger; // integer (i.e. no decimals allowed)
                            scanf("%i", &primitiveInteger); // notice the address of operator getting the address of the primitiveInteger variable by prepending the variable name with the & (address of) operator.
                            printf("Your integer is %i", primitiveInteger); simply printing it out here to the stdout stream (most likely your terminal.)



                            Example 2. Not using a primitive value



                            #include <stdio.h>

                            int main()

                            char *nonPrimitiveString; // initialize a string variable which is NOT a primitive in C
                            scanf("%s", nonPrimitiveString); // notice there is no address of operator here
                            printf("%sn", nonPrimitiveString); // prints string






                            share|improve this answer















                            Like others have said, it's because when you have a value that is a primitive (like an int) that is being read with scanf you have to pass the memory address to that primitive value. However, just to add something that has not been mentioned yet, the same is not true for strings.



                            Example 1. Using with a primitive value



                            #include <stdio.h>

                            int main()

                            int primitiveInteger; // integer (i.e. no decimals allowed)
                            scanf("%i", &primitiveInteger); // notice the address of operator getting the address of the primitiveInteger variable by prepending the variable name with the & (address of) operator.
                            printf("Your integer is %i", primitiveInteger); simply printing it out here to the stdout stream (most likely your terminal.)



                            Example 2. Not using a primitive value



                            #include <stdio.h>

                            int main()

                            char *nonPrimitiveString; // initialize a string variable which is NOT a primitive in C
                            scanf("%s", nonPrimitiveString); // notice there is no address of operator here
                            printf("%sn", nonPrimitiveString); // prints string







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 28 at 7:04

























                            answered Mar 28 at 6:33









                            brff19brff19

                            1011 silver badge11 bronze badges




                            1011 silver badge11 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25574981%2fformat-specifies-type-int-but-argument-has-type-int%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                                155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해