I NEED HELP WITH C PROGRAMMING. Answer each of the following.
Assume that unsigned integers are stored in 4 bytes and that the starting address of the array is at location 200 600 in memory.
i)What address is referenced by vPtr + 5? What value is stored at that location?
j) Assuming vPtr points to values[6] , what address is referenced by vPtr -= 4? What value is stored at that location?
Also .....
For each of the following, write a single statement that performs the indicated task. Assume that short integer variables value1 and value2 have been defined and that value1 has been initialized to 80000.
a) Define the variable lPtr to be a pointer to an object of type short.
b) Assign the address of variable value1 to pointer variable lPtr.
c)Print the value of the object pointed to by lPtr.
d) Assign the value of the object pointed to by lPtr to variable value2.
e)Print the value of value2.
f)Print the address of value1.
g)Print the address stored in lPtr. Is the value printed the same as the address of value1?
My code is below. I keep getting the error message " Q2.c: In function ‘main’: Q2.c:6:1: warning: overflow in implicit constant conversion [-Woverflow] short int value1=80000,value2; ^ /tmp/ccSYVDKb.o: In function `main':
/u/jforrow/C291-Spring1-2019/exercise/hwk4/Q2.c:21: undefined reference to `clrscr'
/u/jforrow/C291-Spring1-2019/exercise/hwk4/Q2.c:42: undefined reference to `stdscr'
/u/jforrow/C291-Spring1-2019/exercise/hwk4/Q2.c:42: undefined reference to `wgetch'
collect2: error: ld returned 1 exit status"
#include
#include
void main()
{
short int value1=80000,value2;
//short range is -32,768 to 32,767
// 80000 is initialized to value1 but it can not value
//beacuse of range
// so the out put is not 80000
// 80000-32767=47233
//47233-32767=14466
//two times zeros we need subtract
//14466-2=14464
//14464 is out put
//a)
short *lPtr;
clrscr();//clear the previous output
//b)
lPtr=&value1;
//c)
printf("\n The value of the object pointed by lPtr is
%d\n",*lPtr);
// \n for new line
//d)
value2=*lPtr;
//e)
printf("\n The value of value2=%d\n",value2);
//f)
printf("\n The address of value1 is %d\n",&value1);
//g)
printf("\n The address stored in lPtr is %d, and the address of
value1 is %d",lPtr,&value1);
getch();
}
Assume that unsigned integers are stored in 4 bytes and that the starting address of the array is at location 200 600 in memory.
hence values array is located at starting address 200600
assume array ---> values=[0,1,2,3,4,5,6]
-----------------------------------------------------------------------------
i)What address is referenced by vPtr + 5? What value is stored at that location?
if vPtr stores starting address of values array :
unsigned int *vPtr=values;
hence printf ("%u",*vPtr) ---> 0
hence printf("%u", *(vPtr+5)) -----> 5
hece vPtr will store the address (starting_address + (index * sizeof(unsigned int =4 )) ) =200600+ (0*4)= 200600
hece vPtr+1 will store the address (starting_address + (index * sizeof(unsigned int =4 )) ) =200600+ (1*4)= 200604
hece vPtr+2 will store the address (starting_address + (index * sizeof(unsigned int =4 )) ) =200600+ (1*4)= 200608
hece vPtr+5 will store the address (starting_address + (index * sizeof(unsigned int =4 )) ) =200600+ (5*4)= 200620
and so on ....
about values :
*vPtr=values[0]=0
*(vPtr+1)=values[1]= 1
*(vPtr+2)=values[2]= 2
and hence * (vPtr + 5) =values[5] = 5 is value stored
REFERENCE OUTPUT
------------------------------------------------------------------------------------------------------------
Question j) Assuming vPtr points to values[6] , what address is referenced by vPtr -= 4? What value is stored at that location?
if vPtr points to values[6] then vPtr stores the address 200600+ (6*4)= 200624
and values stored will be values[6]=6
******* after vPtr - = 4 ******
vPtr stores the address = 200624 - (4*4) =2006008 which will hold the address of values[2]
and values stored will be *(vPtr) = values[2]=2
------------------------------------------------------------------------
Question ) For each of the following, write a single statement that performs the indicated task. Assume that short integer variables value1 and value2 have been defined and that value1 has been initialized to 80000.
Your code works fine -->just gives the warning
main.c:4:18: warning: overflow in implicit constant conversion [-Woverflow]
short int value1=80000,value2;
This is because the range of short range is -32,768 to 32,767
So either Ignore the warning or else assign the value1 and value2 in between -32,768 to 32,767 to avoid warning otherwise your code is fine
1) with warning OUTPUT
2)without warning OUTPUT
I NEED HELP WITH C PROGRAMMING. Answer each of the following. Assume that unsigned integers are...
please write the code in C++ AND BE VERY SURE OF IT SINCE IT IS AN ASSIGNMENT WITH LOTS OF MARKS - DON'T COPY FROM THE INTERNET I- For each of the following, write a single statement that performs the specified task. Assume that long integer variables value1 and value2 have been declared and value1 has been initialized to 200000. a)- Declare the variable longPtr to be a pointer to an object of type long. b)- Assign the address of...
Hello. I just need help with my c++ code. Write a program that: Creates an integer variable AND an integer pointer variable Ask the user to input an integer value Store the value in the integer variable Print the address of the variable. Make the pointer variable point at the integer value Print the value pointed to by the pointer Print the address of the pointer
using visual studio 2) For each of the following, write C++ statements that perform the specified task.. (Ref: classwork named pointer2) a) Declare a built-in array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. b) Declare a pointer vPtr that points to a variable of type unsigned int. c) Write two separate statements that assign the starting address of array values to pointer variable vPtr. d) Use...
Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...
Hi all, I need help to do a project based on C++ smart pointers. I have to implement the class template my_unique_ptr which is a pointer management class template. Also, it's required to implement the following public methods: a. Default constructor that initializes the object to point to nullptr. b. Constructor that takes a pointer Type * as a parameter and sets the object to point there. We say that the newly created object takes ownership of the pointed memory....
Need help about C PROGRAMMING,, pls use only C LANGUAGE.., yea so im doing this exercise as a practice for c programming, could someone do this as well so i could compare if my code makes makes sense and to see and help correct the errors im getting right now.. Any helpful help would be appreciated.. Pointers &Pointer arithmetic Memory allocation and freeing Main topics: Exercise This lab is designed to give you practice working with pointers and memory allocation...
This is In C++ only Thank you 2. Employee is a base class and Hourly Worker is a derived class. Which statement about the destructors of both classes is true? al They should be declared virtual u Declaring them virtual or not does not make any difference c) They should be implemented as friend functions d) The destructor of HourlyWorker must be virtual whereas the destructor of Employee should 3. If a base class has a non-virtual member function called...
please answer all the questions. 2. (35 pts, 5 each) Consider the following array a. Write single-line statements to do the following double a[8] {0.0, = 10.0, 20.0, 30.0, 40.0), *p , ,g: Set the pointer p to point to the first element of the array - I ?-K-U) Set pointer q to point to the element with value 20.0 in the array as afn] with the correct n value. Use p above to triple the value stored in a[1]...
I need help on this Systems review please! it's due by midnight monday. Question 1 Not yet answered Points out of 1.00 Flag question Question text Using these declarations: int * numberPointers[3]; int * pointer; int number; Which of the following statements would generate a warning or error? Select one: a. number = pointer; b. *pointer = number; c. pointer = numberPointers; d. numberPointers[2] = &number; e. a., b., and d. f. a. and c. Question 2 Not yet answered...
Programming in C 5. (14 pts) Write a single statement to do each of the following: a. (7 pts) Assign character 'Y' to the variable pointed to by char pointer passptr, assuming passptr has already defined. b. (7 pts) Print the value of passptr above.