cloud9-Problem executing code

Asked

Viewed 623 times

1

The following code:

#include <stdio.h>

void main()
{
    int num = 123;
    printf("O valor de num = %d e o valor seguinte = %c", num, num+1);
}

Returns in Cloud9 terminal the following result:

The value of num = 123 and the following = |

Can anyone help me understand what is going wrong? Why is it that in the terminal it does not assume the sum of the variable?

The browser used is Chrome Version 34.0.1847.137 m

1 answer

7


There is an error in your printf. It should be

printf("O valor de num = %d e o valor seguinte = %d",num,num+1); 

As before, with %c, the printf would display the ASCII character corresponding to the given value. In this case, 124 corresponds to the vertical bar |.

Edit: You can find here the various formatting modifiers used in C and the corresponding output.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.