22F-7465 Hometask

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

OBJECT ORIANTED

PROGRAMMING LAB

SUBMITTED TO :
SHAHBAZ AYYAZ

SUBMITTED BY :
HASHIR KHAN

ROLL NO :
22F-7465

DATE :
8-2-2023
Question # 1:

Firstly no value is initialized or stored in the pointer thus it will display adress of garbage
value

Long and double data type cannot be equal

Right approach to store value in pointer is *x=&a;

Conditions of for loop is not right there is a semicolon before anything

A pointer cannot store another pointer like this similarly there are two semicolons in the
same line before initialiization

There was no (*) sign for the initialization of pointer


Question # 2:
A)
#include <iostream>
using namespace std;

void mystery1(char*, const char*); // prototype


int main()

{
char string1[80];

char string2[80];
cout << "Enter two strings: ";

cin >> string1 >> string2;


mystery1(string1, string2);

cout << string1 << endl;


} // end main

// What does this function do?


void mystery1(char* s1, const char* s2)

{
while (*s1 != '\0')

++s1;
for (; *s1 = *s2; ++s1, ++s2);

WHAT DOES THIS PROGRAMM DO ?

This program is perfrorming the function of concatinating of string which means it joins two
strings and displays the output. For loop in the void function is terminated because it has
semicolon in the end
B)
#include <iostream>

using namespace std;

int mystery2(const char*); // prototype

int main()

char string1[80];

cout << "Enter a string: ";

cin >> string1;

cout << mystery2(string1) << endl;

int mystery2(const char* s)

int x;

for (x = 0; *s != '\0'; ++s)

++x;

return x;

WHAT DOES THIS PROGRAMM DO ?

This program tells us about the length of the string


Question # 3:
Function after adding comments and prefix and postfix are identified

Question # 4:
A)
Since we have used the const with the varialble thus passing it with adress of other variables
will not change the output if the const is stored in pointer

B)
It will give error as adress of constant pointer cannot be changed

C)
Const keyword should also be used to point a char secondly we can pass the adress of other
character to the pointer and the pointer will point the modified value of that adress

You might also like