Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

True/False 15. _The following code is valid: int x =5; const int *ptr = &x; * pt

ID: 3723785 • Letter: T

Question

True/False 15. _The following code is valid: int x =5; const int *ptr = &x; * ptr = 7; 16. _Comparing two pointers using relational op- erators are meaningful when both pointers point to elements of the same built-in array 17. _A pointer can be assigned to another pointer of the same type 18. Putting class definition in a separate file (e.g. header) makes it easy to reuse. 19. _A member function of a class can access pri- vate data members of the same class. 20. _Each object of a class has same number of data member and same variable name but different memory location for each data member.

Explanation / Answer

15. false

with constant pointer ,we can only read the pointed variable value ,can't make modificaitions .So,invalid

16. true.

yes they can be compared and ,see the code below.

int n[]={1,2,3,4};
int *ptr= n;
int * p = n;
if(*ptr == *p)
cout<<*p; //it prints value 1 as both pointers pointing to n[0].

  int n[]={1,2,3,4};
int *ptr= n;
int * p = &n[1];
if(*ptr < *p)
cout<<*p; //it prints value 2 as *ptr value is less than *p value.

17. true

  int n=9;
int *ptr= &n;
int * p = ptr;

in the above code *p holds value 9

18. true.

keeping any functions, variables and class definitions in a file with extension .h ,and using them as headers in a program will give us the access to the corresponding data in that file. by which means it makes easy to reuse

19. true.

yes , the member functions in the same class of the private data members, will have access to them.

20. true.

everytime you create an object for a class , a seperate block of memory is created for data members.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote