Why is it returning 0 or 1 and not True or False [duplicate]












0
















This question already has an answer here:




  • Can I display the value of an enum with printf()?

    6 answers



  • How to convert enum names to string in c

    7 answers




#include <stdio.h>
#include <stdbool.h>
typedef enum{
False,
True
}Bool;
int main(int argc, char const *argv)
{
int a = 1, d = 1;
Bool b = False, c = True;
Bool ans;
if (a == d)
{
ans = c;

}
else
{
ans = b;
}
printf("The answer is: %i n", ans);
return 0;
}


I think it is only returning the execution result 0 or 1.
I want it to return the values from the enum which I created.










share|improve this question













marked as duplicate by Sander De Dycker, Andrew Henle, Govind Parmar, Lundin c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 16:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 9





    How do you think the values in your enum are represented internally?

    – Govind Parmar
    Nov 21 '18 at 15:12











  • If I change it to be TRuuue and Faaalse, it still returns 0 and 1.

    – CEXDSINGH
    Nov 21 '18 at 15:13








  • 3





    Changing the names has absolutely nothing to do with Govind's question. Changing the order in the enum ({ True, False }) would be significant. Is that what you meant ?

    – WhozCraig
    Nov 21 '18 at 15:14








  • 1





    In that case, I am clueless.

    – CEXDSINGH
    Nov 21 '18 at 15:16






  • 3





    also : How to convert enum names to string in c

    – Sander De Dycker
    Nov 21 '18 at 15:18
















0
















This question already has an answer here:




  • Can I display the value of an enum with printf()?

    6 answers



  • How to convert enum names to string in c

    7 answers




#include <stdio.h>
#include <stdbool.h>
typedef enum{
False,
True
}Bool;
int main(int argc, char const *argv)
{
int a = 1, d = 1;
Bool b = False, c = True;
Bool ans;
if (a == d)
{
ans = c;

}
else
{
ans = b;
}
printf("The answer is: %i n", ans);
return 0;
}


I think it is only returning the execution result 0 or 1.
I want it to return the values from the enum which I created.










share|improve this question













marked as duplicate by Sander De Dycker, Andrew Henle, Govind Parmar, Lundin c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 16:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 9





    How do you think the values in your enum are represented internally?

    – Govind Parmar
    Nov 21 '18 at 15:12











  • If I change it to be TRuuue and Faaalse, it still returns 0 and 1.

    – CEXDSINGH
    Nov 21 '18 at 15:13








  • 3





    Changing the names has absolutely nothing to do with Govind's question. Changing the order in the enum ({ True, False }) would be significant. Is that what you meant ?

    – WhozCraig
    Nov 21 '18 at 15:14








  • 1





    In that case, I am clueless.

    – CEXDSINGH
    Nov 21 '18 at 15:16






  • 3





    also : How to convert enum names to string in c

    – Sander De Dycker
    Nov 21 '18 at 15:18














0












0








0









This question already has an answer here:




  • Can I display the value of an enum with printf()?

    6 answers



  • How to convert enum names to string in c

    7 answers




#include <stdio.h>
#include <stdbool.h>
typedef enum{
False,
True
}Bool;
int main(int argc, char const *argv)
{
int a = 1, d = 1;
Bool b = False, c = True;
Bool ans;
if (a == d)
{
ans = c;

}
else
{
ans = b;
}
printf("The answer is: %i n", ans);
return 0;
}


I think it is only returning the execution result 0 or 1.
I want it to return the values from the enum which I created.










share|improve this question















This question already has an answer here:




  • Can I display the value of an enum with printf()?

    6 answers



  • How to convert enum names to string in c

    7 answers




#include <stdio.h>
#include <stdbool.h>
typedef enum{
False,
True
}Bool;
int main(int argc, char const *argv)
{
int a = 1, d = 1;
Bool b = False, c = True;
Bool ans;
if (a == d)
{
ans = c;

}
else
{
ans = b;
}
printf("The answer is: %i n", ans);
return 0;
}


I think it is only returning the execution result 0 or 1.
I want it to return the values from the enum which I created.





This question already has an answer here:




  • Can I display the value of an enum with printf()?

    6 answers



  • How to convert enum names to string in c

    7 answers








c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 15:11









CEXDSINGHCEXDSINGH

135




135




marked as duplicate by Sander De Dycker, Andrew Henle, Govind Parmar, Lundin c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 16:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Sander De Dycker, Andrew Henle, Govind Parmar, Lundin c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 16:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 9





    How do you think the values in your enum are represented internally?

    – Govind Parmar
    Nov 21 '18 at 15:12











  • If I change it to be TRuuue and Faaalse, it still returns 0 and 1.

    – CEXDSINGH
    Nov 21 '18 at 15:13








  • 3





    Changing the names has absolutely nothing to do with Govind's question. Changing the order in the enum ({ True, False }) would be significant. Is that what you meant ?

    – WhozCraig
    Nov 21 '18 at 15:14








  • 1





    In that case, I am clueless.

    – CEXDSINGH
    Nov 21 '18 at 15:16






  • 3





    also : How to convert enum names to string in c

    – Sander De Dycker
    Nov 21 '18 at 15:18














  • 9





    How do you think the values in your enum are represented internally?

    – Govind Parmar
    Nov 21 '18 at 15:12











  • If I change it to be TRuuue and Faaalse, it still returns 0 and 1.

    – CEXDSINGH
    Nov 21 '18 at 15:13








  • 3





    Changing the names has absolutely nothing to do with Govind's question. Changing the order in the enum ({ True, False }) would be significant. Is that what you meant ?

    – WhozCraig
    Nov 21 '18 at 15:14








  • 1





    In that case, I am clueless.

    – CEXDSINGH
    Nov 21 '18 at 15:16






  • 3





    also : How to convert enum names to string in c

    – Sander De Dycker
    Nov 21 '18 at 15:18








9




9





How do you think the values in your enum are represented internally?

– Govind Parmar
Nov 21 '18 at 15:12





How do you think the values in your enum are represented internally?

– Govind Parmar
Nov 21 '18 at 15:12













If I change it to be TRuuue and Faaalse, it still returns 0 and 1.

– CEXDSINGH
Nov 21 '18 at 15:13







If I change it to be TRuuue and Faaalse, it still returns 0 and 1.

– CEXDSINGH
Nov 21 '18 at 15:13






3




3





Changing the names has absolutely nothing to do with Govind's question. Changing the order in the enum ({ True, False }) would be significant. Is that what you meant ?

– WhozCraig
Nov 21 '18 at 15:14







Changing the names has absolutely nothing to do with Govind's question. Changing the order in the enum ({ True, False }) would be significant. Is that what you meant ?

– WhozCraig
Nov 21 '18 at 15:14






1




1





In that case, I am clueless.

– CEXDSINGH
Nov 21 '18 at 15:16





In that case, I am clueless.

– CEXDSINGH
Nov 21 '18 at 15:16




3




3





also : How to convert enum names to string in c

– Sander De Dycker
Nov 21 '18 at 15:18





also : How to convert enum names to string in c

– Sander De Dycker
Nov 21 '18 at 15:18












3 Answers
3






active

oldest

votes


















3














If you want it to print the string true or false you'll have to add something like this:



printf("The answer is: %sn", ans ? "true" : "false");





share|improve this answer
























  • Upped. Compared to my answer, this one is useful.

    – Bathsheba
    Nov 21 '18 at 15:18











  • @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

    – Fiddling Bits
    Nov 21 '18 at 15:19



















2














From the C Standard, § 6.7.2.2:2-3:




The identifiers in an enumerator list are declared as constants that have type int and
may appear wherever such are permitted.) An enumerator with = defines its
enumeration constant as the value of the constant expression. If the first enumerator has
no =, the value ... is 0
. Each subsequent enumerator with no =
defines its ... value ... by
adding 1 to the value of the previous enumeration constant.




Emphasis mine.






share|improve this answer































    1














    In C an enum is no more than an int type but with special symbols for a subset of those ints. Also, unless you tell it otherwise, the implicit int value for the first enum member is 0, the second is 1, and so on.



    %i can be used to print an int, which accounts for the output.



    It is not possible to display the actual enum token in portable C, although there are idiomatic approaches that make use of the preprocessor.






    share|improve this answer


























    • The enum token can only be used in the program text.

      – Paul Ogilvie
      Nov 21 '18 at 15:27











    • Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

      – Govind Parmar
      Nov 21 '18 at 15:36


















    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    If you want it to print the string true or false you'll have to add something like this:



    printf("The answer is: %sn", ans ? "true" : "false");





    share|improve this answer
























    • Upped. Compared to my answer, this one is useful.

      – Bathsheba
      Nov 21 '18 at 15:18











    • @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

      – Fiddling Bits
      Nov 21 '18 at 15:19
















    3














    If you want it to print the string true or false you'll have to add something like this:



    printf("The answer is: %sn", ans ? "true" : "false");





    share|improve this answer
























    • Upped. Compared to my answer, this one is useful.

      – Bathsheba
      Nov 21 '18 at 15:18











    • @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

      – Fiddling Bits
      Nov 21 '18 at 15:19














    3












    3








    3







    If you want it to print the string true or false you'll have to add something like this:



    printf("The answer is: %sn", ans ? "true" : "false");





    share|improve this answer













    If you want it to print the string true or false you'll have to add something like this:



    printf("The answer is: %sn", ans ? "true" : "false");






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 15:17









    Fiddling BitsFiddling Bits

    7,10821938




    7,10821938













    • Upped. Compared to my answer, this one is useful.

      – Bathsheba
      Nov 21 '18 at 15:18











    • @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

      – Fiddling Bits
      Nov 21 '18 at 15:19



















    • Upped. Compared to my answer, this one is useful.

      – Bathsheba
      Nov 21 '18 at 15:18











    • @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

      – Fiddling Bits
      Nov 21 '18 at 15:19

















    Upped. Compared to my answer, this one is useful.

    – Bathsheba
    Nov 21 '18 at 15:18





    Upped. Compared to my answer, this one is useful.

    – Bathsheba
    Nov 21 '18 at 15:18













    @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

    – Fiddling Bits
    Nov 21 '18 at 15:19





    @Bathsheba Your answer is useful too. I gave you a +1 as it's more detailed.

    – Fiddling Bits
    Nov 21 '18 at 15:19













    2














    From the C Standard, § 6.7.2.2:2-3:




    The identifiers in an enumerator list are declared as constants that have type int and
    may appear wherever such are permitted.) An enumerator with = defines its
    enumeration constant as the value of the constant expression. If the first enumerator has
    no =, the value ... is 0
    . Each subsequent enumerator with no =
    defines its ... value ... by
    adding 1 to the value of the previous enumeration constant.




    Emphasis mine.






    share|improve this answer




























      2














      From the C Standard, § 6.7.2.2:2-3:




      The identifiers in an enumerator list are declared as constants that have type int and
      may appear wherever such are permitted.) An enumerator with = defines its
      enumeration constant as the value of the constant expression. If the first enumerator has
      no =, the value ... is 0
      . Each subsequent enumerator with no =
      defines its ... value ... by
      adding 1 to the value of the previous enumeration constant.




      Emphasis mine.






      share|improve this answer


























        2












        2








        2







        From the C Standard, § 6.7.2.2:2-3:




        The identifiers in an enumerator list are declared as constants that have type int and
        may appear wherever such are permitted.) An enumerator with = defines its
        enumeration constant as the value of the constant expression. If the first enumerator has
        no =, the value ... is 0
        . Each subsequent enumerator with no =
        defines its ... value ... by
        adding 1 to the value of the previous enumeration constant.




        Emphasis mine.






        share|improve this answer













        From the C Standard, § 6.7.2.2:2-3:




        The identifiers in an enumerator list are declared as constants that have type int and
        may appear wherever such are permitted.) An enumerator with = defines its
        enumeration constant as the value of the constant expression. If the first enumerator has
        no =, the value ... is 0
        . Each subsequent enumerator with no =
        defines its ... value ... by
        adding 1 to the value of the previous enumeration constant.




        Emphasis mine.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 15:16









        Govind ParmarGovind Parmar

        7,26053055




        7,26053055























            1














            In C an enum is no more than an int type but with special symbols for a subset of those ints. Also, unless you tell it otherwise, the implicit int value for the first enum member is 0, the second is 1, and so on.



            %i can be used to print an int, which accounts for the output.



            It is not possible to display the actual enum token in portable C, although there are idiomatic approaches that make use of the preprocessor.






            share|improve this answer


























            • The enum token can only be used in the program text.

              – Paul Ogilvie
              Nov 21 '18 at 15:27











            • Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

              – Govind Parmar
              Nov 21 '18 at 15:36
















            1














            In C an enum is no more than an int type but with special symbols for a subset of those ints. Also, unless you tell it otherwise, the implicit int value for the first enum member is 0, the second is 1, and so on.



            %i can be used to print an int, which accounts for the output.



            It is not possible to display the actual enum token in portable C, although there are idiomatic approaches that make use of the preprocessor.






            share|improve this answer


























            • The enum token can only be used in the program text.

              – Paul Ogilvie
              Nov 21 '18 at 15:27











            • Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

              – Govind Parmar
              Nov 21 '18 at 15:36














            1












            1








            1







            In C an enum is no more than an int type but with special symbols for a subset of those ints. Also, unless you tell it otherwise, the implicit int value for the first enum member is 0, the second is 1, and so on.



            %i can be used to print an int, which accounts for the output.



            It is not possible to display the actual enum token in portable C, although there are idiomatic approaches that make use of the preprocessor.






            share|improve this answer















            In C an enum is no more than an int type but with special symbols for a subset of those ints. Also, unless you tell it otherwise, the implicit int value for the first enum member is 0, the second is 1, and so on.



            %i can be used to print an int, which accounts for the output.



            It is not possible to display the actual enum token in portable C, although there are idiomatic approaches that make use of the preprocessor.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 21 '18 at 15:22

























            answered Nov 21 '18 at 15:16









            BathshebaBathsheba

            176k27251373




            176k27251373













            • The enum token can only be used in the program text.

              – Paul Ogilvie
              Nov 21 '18 at 15:27











            • Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

              – Govind Parmar
              Nov 21 '18 at 15:36



















            • The enum token can only be used in the program text.

              – Paul Ogilvie
              Nov 21 '18 at 15:27











            • Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

              – Govind Parmar
              Nov 21 '18 at 15:36

















            The enum token can only be used in the program text.

            – Paul Ogilvie
            Nov 21 '18 at 15:27





            The enum token can only be used in the program text.

            – Paul Ogilvie
            Nov 21 '18 at 15:27













            Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

            – Govind Parmar
            Nov 21 '18 at 15:36





            Token names may also be available in debugging databases, depending on build settings (like a .pdb file on Windows)

            – Govind Parmar
            Nov 21 '18 at 15:36



            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin