Question

What number does each line of code print out? Briefly explain why. printf("%u\n",(unsigned char)(-2)); printf("%d\n",(unsigned char)(-2));...

What number does each line of code print out? Briefly explain why.

printf("%u\n",(unsigned char)(-2));
printf("%d\n",(unsigned char)(-2));
  
printf("%u\n",(uint16_t)(-2));
printf("%d\n",(uint16_t)(-2));
  
printf("%u\n",(unsigned int)(-2));
printf("%d\n",(unsigned int)(-2));

0 0
Add a comment Improve this question Transcribed image text
Answer #1

printf("%u\n",(unsigned char)(-2));
unsigned char value of -2 converted to unsigned int is 254

printf("%d\n",(unsigned char)(-2));
unsigned char value of -2 converted to int is 254

printf("%u\n",(uint16_t)(-2));
uint16_t is unsigned 16-bit integer
unsigned 16-bit of -2 converted to unsigned int is 65534

printf("%d\n",(uint16_t)(-2));
unsigned 16-bit of -2 converted to int is 65534

printf("%u\n",(unsigned int)(-2));
unsigned int value of -2 converted to unsigned gives memory address 4294967294

printf("%d\n",(unsigned int)(-2));
unsigned char value of -2 converted to int is -2

Add a comment
Know the answer?
Add Answer to:
What number does each line of code print out? Briefly explain why. printf("%u\n",(unsigned char)(-2)); printf("%d\n",(unsigned char)(-2));...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

  • 10 What does the last printf in this code print to the screen? a)n-7 b)n- 0...

    10 What does the last printf in this code print to the screen? a)n-7 b)n- 0 c)n--1 d) None of the above 鬐include< stdio. h> int main) int n-0 for (n-7: n<O; n-- printf (n") printf ("n *%d", n); - return 11-What does the code print to the screen? 鬐include< stdio.h> void fun (int) int main) b) 8 d) None of the above fun (3) return void fun (int a) int x-10 while(a !_ 3 x > s} if a...

  • Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf(&#3...

    Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf("%i %u", &N,&seed); srand(seed);    for(i=0;i { R=(double)rand()/RAND_MAX; if (R<0.5) x=x+1; else x=x-1; } printf("Final location is "); printf("%d",x); printf("\n"); } Question: Write a code that generates N pairs of random numbers. Call the first member of each pair x and the second member y. Count how many of the N pairs obey x^2+y^2<1. Call...

  • C PROGRAM When you print out the old and new bitsets, which are of type unsigned...

    C PROGRAM When you print out the old and new bitsets, which are of type unsigned char, please use the %p control character in the printff statement rather than %x or %d or %c. The compiler will complain, but we don't always listen to them anyway. The difference is it will print the bitset out in hex with a preceeding %0x. unsigned char bitset = 0x14 ; printf("Bitsrt is %p\n", bitset) ; results in Bitset is 0x14, which is what...

  • 7 - What does the code print to the screen? float x(float) 7/3; printf ( "...

    7 - What does the code print to the screen? float x(float) 7/3; printf ( " % .2 f", x); a) 7/3 b) 2.50 c) 2.00 d) None of the above a) TRUE b) FALSE c) TRUEFALSE d) None of the above 8 - What does the code print to the screen? int x3; if (x >31x!-2 printf ("TURE") printf ("FALSE"); 9What does the code print to the screen? a) TRUETRUE b) TRUE c) TRUETRUETRUE d) TRUETRUETRUETRUE e) None of...

  • Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...

    Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array. 2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table. 3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table. C++ Program #include <stdio.h> #include <iostream> int...

  • Problem 4 (25 points). What will the following code print? Why? Identify the line where the...

    Problem 4 (25 points). What will the following code print? Why? Identify the line where the vulnerability is. Explain the vulnerability. Show how the vulnerability can be eliminated Algorithm 2 Example vulnerability l.void called (int foo) 2. if (foo 1) printf("foo") 3. else printf("bar" S.int main O 6. called(2): 7. return 0:)

  • Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...

    Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{    char Word[21];    int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() {    struct myWord wordList[20];    char line[100];    printf("Enter an English Sentence:\n");    gets(line);    int size = tokenizeLine(line, wordList);    printf("\n");    printf("Unsorted word list.\n");    printList(wordList, size);...

  • Please comment and or provide information on what each function or line does within the following...

    Please comment and or provide information on what each function or line does within the following code. The code is a Arduino Atmega C programming language code which which creates a piano keyboard outputting different frequencies per. I would really appreciate a detailedf explanation on what each function and line does as I am a beginner and need to use this within lab. volatile unsigned char *TCCR1A = (unsigned char *) 0x80; /* Address location for Timer/Counter Control Register A....

  • c++ only. Please follow directions. What does the following program print and why? Comment each line...

    c++ only. Please follow directions. What does the following program print and why? Comment each line of code to explain what it is doing.   #include <iostream> using namespace std; int main() { int track[ ] = { 10, 20, 30, 40 }; int * ptr; ptr = track; track[1] += 30; cout << * ptr << " "; *ptr -= 10; ptr++; cout << * ptr << " "; ptr += 2; cout << * ptr << " "; cout...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT