What is the value of “x” after the following code is executed? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the value of “x” after the following code is executed?

Hello, can anyone please help me with the following questions? What is the value of “x” after the following code is executed? char n1 = 0xF1; char n2 = 0x1F; char x = 0; x = n1 & n2; Also, if I have a function like this: int function (void) what does it return? Thank you in advance.

7th May 2023, 12:56 PM
BMN16
4 Answers
+ 3
Did you try to test the code in Playground? what did you find? It's impossible to know what the function actually returns (except for the return type `int`) without seeing the complete definition of the function.
7th May 2023, 1:46 PM
Ipang
+ 2
int function (void) returns an int ^^^ Like this say void indicates that there are NO ARGUMENTS in the function. It is used on C language. Read Ipang's comment.
7th May 2023, 3:08 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 2
0x before a number means it is in hexadecimal form. C allows implicit convertions. & is bitwise and operator. You can find, here how it works with an example. https://www.sololearn.com/learn/4072/?ref=app Output, you can check in playground. n1 = 0xF1 = 241=> 11110001 n2 = 0x1F = 31 => 00011111 & ----------------------------------- 00010001 => 17 As already, told int is return type for your function int function(void) {.. } so returns an integer value.
7th May 2023, 4:10 PM
Jayakrishna 🇮🇳
+ 1
Thank you all. For my second question, this is the full function. I thought initially because of the int that it will return 4. But the void confused me. int Func1(void) { int a = 30; int b = 9 - a / 5; int c; c = b * 4; if (c > 10) { c = c - 10; } return c * (60 / a); }
7th May 2023, 5:48 PM
BMN16