Question

Three variables x, y, and z defined as unsigned char, short, and int types in C...

  1. Three variables x, y, and z defined as unsigned char, short, and int types in C Programming. What are the maximum values they can take?
  1. Compare the following C programs. After execution of this short programs what will be the value of x if printed in function?

void foo(void);

int main(void){

            foo();

            foo();

            foo();

return 0;

}

void foo()

{

            int x = 1;

            x++;   

           }

void foo(void);

int main(void){

            foo();

            foo();

            foo();

return 0;

}

void foo()

{

            static int x = 1;

            x++;   

           }

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

Any queries feel free to ask

Please give your positive feedback

Thank you

3 unsigned char:- Maximum value for an unsigned char = 255. We can take .255 as maximum. Short: we can take .32767 as Maximum int: we can take .2147483 647 as Maximum

main.c 1 2 3 #include <stdio.h> int main() À JOVOU A int x; void foo(void); int main(void){ foo(); foo(); foo(); return 0; void foo(); 13 14 static int x=1; x++; 15 16 17 printf("%d",x); 18 } 19

input 32765 ... Program finished with exit code o Press ENTER to exit console.

main.c 1 2 #include <stdio.h> int main() int x; void foo(void); int main(void){ foo(); foo(); foo(); return 0; 10 11 12 void foo(); - - 13- 14 int x=1; X++; 15 16 17 printf("%d",x); 18 } 19

input 32766 ... Program finished with exit code o Press ENTER to exit console.

Both programs are giving same x value in the function. Because in both programs the function void foo(); is executed one time. So in both programs x value printed as 2. first x will equal to 1 and x will incremented by one.

1)

  • Unsigned char value is between 0 to 255. Max value is 255.
  • Short value is between -32,768 to 32,767. Max value is 32,767
  • Int value is between -32,768 to 32,767. Max value is 32,767

any queries feel free to ask

please give your positive feedback

thank you

Add a comment
Know the answer?
Add Answer to:
Three variables x, y, and z defined as unsigned char, short, and int types in C...
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
  • Output all combinations of character variables a, b, and c. If a x,b-y, and c z, then the output ...

    write solution to the program above in C please and thank you. Output all combinations of character variables a, b, and c. If a x,b-y, and c z, then the output is Your code will be tested in three different programs, with a, b, c assigned with Χ. 'y', 'z', then with #. 'S. %, then with T, 23 1 #include 3 int main(void) { char a char b; char c; 4. 7 scanf(" scanf(" scanf(" %c %c %c ",...

  • #include <stdio.h> int main(int argc, char *argv[]) {      char a, *pc, c[9];      int i, *pk, k[9];      a='...

    #include <stdio.h> int main(int argc, char *argv[]) {      char a, *pc, c[9];      int i, *pk, k[9];      a='z';      pc=&(c[8]);      pk=&(k[0]);      for (i=0; i<9; i++)     {           *pc=a-(char)i;           pc--;           *pk=(int)a-i;           pk++;           }                     return 0; }//end of main Answer the below questions with the above code Write out the memory map for the above C code in the following table. For array variables, list the address range for the entire array. Assume the memory address starts from 100, that is, the address for a...

  • QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x,...

    QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x, int& y); int Doughnut(int y, int z); int main( ) {             int a = 1;             int b = 2;             int c = 3;             int d = 4;             Pancake(a, b, c);             Waffle(b, c);             Pancake(d, c, b);             d = Doughnut(b, a);             return 0; } void Pancake(int x, int& y, int z) {             y += 3;            ...

  • In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         .........

    In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         ......      }     public static void  main(String[] args)     {          int a, b;          ......          sample(a,b);     } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?

  • In "C" Language (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program th...

    In "C" Language (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int and a long. Do the values always print correctly:? Sample input/output. To print in hexadecimal, use %x as the formatter. Input must be same...

  • Consider the following in C int main() { float x = 3.14, *p = &x; int...

    Consider the following in C int main() { float x = 3.14, *p = &x; int r, a = 2, b[] = {5, 6, 7}; <more code here> r = Foo(x, p, &a, b) <more code here> } int Foo(float x,float y, int *z, int *w) { <Foo's code goes here> } statement in Foo result (assigned value) modify Foo's AF variables modify main's AF variables statement in Foo result (assigned value) modify Foo's AF variables modify main's AF variables...

  • Using C: Implement the function ranges that takes no input and prints the ranges (i.e., the...

    Using C: Implement the function ranges that takes no input and prints the ranges (i.e., the minimum and maximum legal values) of the types char, short, int, long, and long long, both signed and unsigned. You should do this by printing appropriate constants defined in the header file /usr/include/limits.h (this is why hw1.c starts with #include <limits.h>). This should print something like: signed char minimum value: -128 maximum value: 127 unsigned char minimum value: 0 maximum value: 255 signed short...

  • 2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo...

    2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf("%d, %d\n",a,b); void foobar) } printf("%d, %d\n", a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf ("%d, %d\n", a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?

  • Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void)...

    Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...

  • using c++ Write a C++ program which reads three values of types char, int, double and...

    using c++ Write a C++ program which reads three values of types char, int, double and string from the keyboard and primis, appropriately formatted, assigned values and variable types. For example, if letter, number, and real are variables of type char, int and double respectively, and if the values assigned to them using cin function are: a, 1, and 3.1415, then the output should be: a is a character 1 is an integen 3.1415 is a real number

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