Awesome q2a theme
0 votes

Suppose we have a code like this

#include <stdio.h>
#include <stdlib.h>

int main()
    unsigned char a=4;
    unsigned  char b=128;
    unsigned short int c;
    return 0;

the output it is giving is 512

but I think it should give 0 :

.a is unsigned char 
b is unsigned char 

so when 4*128=512 = 00000010 00000000

as a and b are unsigned char so a*b is unsigned char  only one byte (which is the lower byte (00000000).)will be assigned to c which is an signed int right?

what concept am I missing?



in Programming by (114 points) | 29 views
Multiplication allowed on characters?

a computer treats a charater as a number. 
so I think it is posssible.

check this code.


Can you please explain it more
Multiplication operator, operands are integers by default, so they treated as 4 bytes rather 1Byte.
so basically when it is being multiplied both are treated as 4bytes and a space of 4B is allocated.

and after that when we are assignning the value to the LHS it is being treated as 2B right?

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users May 2020
  1. Kushagra गुप्ता

    97 Points

  2. praveen modala

    15 Points

  3. ramcharantej_24

    15 Points

  4. abhishek tiwary

    12 Points

  5. srestha

    12 Points

  6. Dtiwari

    9 Points

  7. Shivateja MST

    8 Points

  8. ankitgupta.1729

    8 Points

  9. Rashimdixit

    7 Points

  10. Bhavya1902

    7 Points

7,376 questions
1,741 answers
90,352 users