813 views
3 votes
3 votes

2 Answers

Best answer
3 votes
3 votes

As per C standard, there are three distinct types.

  1. a char
  2. a signed char
  3. an unsigned char

 gcc by default takes plain char as signed char. in a 2's complement machine following things would happen when ever char value exceeds $127$.

  • Likewise in the above program, it will print $-121$

The following program will stop for an unsigned char. But loop forever for a signed char

#include <stdio.h>
int main() {
	unsigned char c = 0; // loops forever for char c = 0;
	while(c < 130) {
		printf("hello\n");
		c++;
	}
	return 0;
}
selected by
1 votes
1 votes

We should know the below concepts before solving this question:-

Concept1:- char c ; means by default signed char c;

Conecpt2:- C Follows 2's Complement representation.

Concept3(Follows from Concept2):-(Imp):- Whatever U store it stored in Binary Number but while retrieval  it gives 2's Complement of Binary Number

So here c=125+10=135

(135)10 = (1000 0111)

So in memory 1000 0111 will store which is binary equivalent of 135

but when we will print char C means ->>( 1000 0111 )it will give us the 2's Complement representation of c which is -121.

Hence -121 is Ans.

edited by

Related questions

0 votes
0 votes
1 answer
1
radha gogia asked Jul 21, 2015
324 views
char ch;scanf("%c",&ch) // after I do scanning of this variable then after I press enter key then it gets stored inside the buffer so can we print this enter key .Since d...
1 votes
1 votes
0 answers
2
aakash pandey asked Apr 30, 2022
289 views
We use character array to declare string in C. So, if I declare an array likecharacter ch[ ] = {‘a’,’k’,’a’,’/o’};and try printing ch[3] like :printf(“%...
0 votes
0 votes
0 answers
3
Gurdeep Saini asked Jan 11, 2019
570 views
Let p be character pointer, consider the following statementp[i]=*(p+i)i[p]=*(i+p)p+i=&(i[p])how many are true ??
3 votes
3 votes
0 answers
4
nishitshah asked Jan 26, 2018
643 views
Answer given is option C. How ?I gather that the character pointer will point to the first byte of the integer whose value is 255.But after that what should be the soluti...