Questions tagged [character-literals]

6 questions
1
vote
3 answers

What does '9' mean in C?

When writing '9' instead of 9 as my char c my endresult becomes negative and wrong for some reason. Why is that? What does '9' do? #include int main() { int a, b; char c = '9'; a = 44; b = a - c; printf("%d \n", b); …
Cryme
  • 21
  • 3
1
vote
1 answer

How to compile the extended character in C++ using GCC?

The following code fails to compile using GCC: int main() { for(int j=0; j<80; j++) //for every column, { //ch is ‘x’ if column is char ch = (j%8) ? ‘ ‘ : ‘x’; //multiple of 8, and cout << ch; //‘ ‘ (space) otherwise } …
1
vote
0 answers

Ascii immediate in gas?

Is there a way to enter in a character as an immediate in gas? For example: mov $1, %rax # decimal mov $0xA, %rbx # hex mov $0b100, %rcx # binary mov 'A', %rdx # something like this? I know I can define this in the .ascii or .string…
David542
  • 104,438
  • 178
  • 489
  • 842
1
vote
2 answers

How do C++ compiler interpret comparison logic in string/character?

When we compare numbers in a string/character format, how does the c++ compiler interpret it? The example below will make it clear. #include using namespace std; int main() { // your code goes here if ('1'<'2') cout<<"true"; …
0
votes
1 answer

Escape Character's unusal behavior

I'm getting an unintended output from this code. int main() { int var; while ((var = getchar() ) != '\n') { if (var == '\t') printf("\\t"); if (var == '\b') printf("\\b"); if (var ==…
0
votes
3 answers

How does C language transform char literal to number and vice versa

I've been diving into C/low-level programming/system design recently. As a seasoned Java developer I still remember my attemtps to pass SUN Java Certification and questions if char type in Java can be cast to Integer and how can that be done. That…
Chlebik
  • 646
  • 1
  • 9
  • 27