Ivo Pereira Posted February 14, 2008 at 10:38 PM Report Share #166950 Posted February 14, 2008 at 10:38 PM Boas pessoal, gostaria de saber como exibir o valor de uma variável, ou melhor do resultado das condições que determinam a variável. Eu fiz o que está mostrado no exemplo a seguir, mas não funciona: #include <stdio.h> int soma(int a, int b) { return(a + b); } void main(){ int resultado; resultado = soma(12, 23); printf("Resultado: " resultado); } Obrigado Link to comment Share on other sites More sharing options...
mobes Posted February 14, 2008 at 10:41 PM Report Share #166952 Posted February 14, 2008 at 10:41 PM printf("Resultado: %d \n", resultado); Link to comment Share on other sites More sharing options...
Ivo Pereira Posted February 15, 2008 at 08:05 AM Author Report Share #167015 Posted February 15, 2008 at 08:05 AM Podes explicar-me o porquê de %d e o porquê da separação da variável por uma vírgula? Link to comment Share on other sites More sharing options...
mobes Posted February 15, 2008 at 09:21 AM Report Share #167025 Posted February 15, 2008 at 09:21 AM http://www.cplusplus.com/reference/clibrary/cstdio/printf.html o %d ou %i é para inteiros. No printf tens uma string de formatação, seguida das variáveis que se quer mostrar separadas por vírgulas. O wikipédia não é grande referencia mas neste caso até tem explicações giras: http://en.wikipedia.org/wiki/Printf Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now