Question

72) Given a character pointer p_ch, and integer pointer p_int, and a float pointer, p_f, how...

72) Given a character pointer p_ch, and integer pointer p_int, and a float pointer, p_f, how many bytes will be added/subtracted, respectively, in the following expressions: (assume that char is 1 byte, int 4 bytes, and float 4 bytes, respectively)   

            a)         p_ch - 4

            b)         p_int + 20

            c)        p_f + 13

            d)         p_int - 1

            e)         p_f – 1

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

First of all let me tell you, a pointer is always of 4 byte long whatever data type it is pointing. It take always 4 byte memory in 32/64bit compiler.

Now come to question. as you mentioned in question, for part a 4 should be character data type so it is of 1 byte size.

(a) pointer size = 4
and a character is being subtracted that is of 1 byte so here 1 byte will be subtracted. ( 4(pointer size) -1(4, that is another character to be subtracted size of 1 byte))

(b) in b part, operation are being performed on int data type, 20 is int so its size is 4 byte as mentioned in question

so 4 byte will be added,

4 byte of p_int pointer size and 4 byte of integer(20)


(c)  in c part, operation are being performed on float data type, 13 is float so its size is 4 byte as mentioned in question

so 4 byte will be added,

4 byte of p_int pointer size and 4 byte of float(13)

(d)  in d part, operation are being performed on int data type, 1 is int so its size is 4 byte as mentioned in question

so 4 byte will be subtracted,

4 byte of p_int pointer and 4 byte of integer(1)

(e) in e part, operation are being performed on float data type, 1 is float so its size is 4 byte as mentioned in question

so 4 byte will be subtracted,

4 byte of p_f pointer and 4 byte of float(13)




Hope this helps!

Ask your doubts in comment section.

Please appreciate the efforts by upvoting the answer, thank you!

Add a comment
Know the answer?
Add Answer to:
72) Given a character pointer p_ch, and integer pointer p_int, and a float pointer, p_f, how...
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
  • Assume that an int variable takes 4 bytes and a char variable takes 1 byte. Given...

    Assume that an int variable takes 4 bytes and a char variable takes 1 byte. Given the following integer array: int arr[5] = {12, 10, 13, 90, 1}; Explain the value of arr .  

  • Give the minimum size of each of the following C data structures, assuming that char values...

    Give the minimum size of each of the following C data structures, assuming that char values occupy byte, int and float values occupy four bytes, double values occupy eight bytes, and pointers occupy bytes. (a) char str[] = "Curly": (b) double *a[4][4]: (c) char *str[3] = {"Moe", "Larry", "Curly"}: (Include the space occupied by the string literals in your answer.) (d) union { int a: char b: float c[4]: }u: (e) struct { int a: char b: float c[4]: }s:...

  • (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byt...

    (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....

  • 2. Give the minimum size of each of the following C++ types, assuming that char values occupy one...

    2. Give the minimum size of each of the following C++ types, assuming that char values occupy one byte, short values occupy two bytes, int and float values occupy four bytes, double and long values occupy eight bytes, and pointers occupy four bytes. a) union u type ( double a[3]; int *b; char c[10] b) struct s1type float *d [2]; long e[4] char f[6] short *gi c) struct s2 type ( s1_type s; u type u [2]; int *h[3]; short...

  • State true or false: (6 x 2 = 12 pts) Using -- with a reverse iterator...

    State true or false: (6 x 2 = 12 pts) Using -- with a reverse iterator moves it from the back toward the front of a list b) The body of a do-while loop is always executed at least once. c) If p points to the array element a[j], then p + i points to a[i+j]. d) Any number of pointer variables may point to the same object. In terms of both execution speed and memory usage usually iterative solutions...

  • Consider a disk with block size = 4096 bytes. A block pointer is 6 bytes and...

    Consider a disk with block size = 4096 bytes. A block pointer is 6 bytes and a record pointer is 8 bytes long. A file has 100,000 records of fixed length. Each record has the following fields and byte size: Name (30), Ssn (9), Dept (9), Address (40), Phone (10), Bdate (8), Sex (1), Job (4) and Salary (4). An additional byte is used as a deletion marked. a. Calculate the record size R in bytes b. Calculate the blocking...

  • Examine the function below and answer the following questions. int gLobal = 25; // declared outside...

    Examine the function below and answer the following questions. int gLobal = 25; // declared outside function int func( int X, char *Y, BYTE Z ) { int a; char b[] = “The lazy dog ate the red fox before jumping over it.” char *c; c = (char *) malloc(512K); a = b[0]; return a; } -- b. How many bytes used on the stack for ‘Z’. c. How many 4K pages of physical memory are needed for the above...

  • If void * is a pointer to void is a "generic" pointer type, and a void...

    If void * is a pointer to void is a "generic" pointer type, and a void * can be converted to any other pointer type * without an explicit cast, why in the ,myarrcopy function the malloc is created like char and not like void? if we are going to work with different type of arrays? Here is de program: *This is a function that make a copy of any given array. * We then use this function make a...

  • C++ SECTION 1) (15 points) Write a full C++ program that reads an integer, a list...

    C++ SECTION 1) (15 points) Write a full C++ program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Ex: If the input is: 4 hello zoo sleep drizzle z then the output is: 200 drizzle To...

  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

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