C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 8)
8.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<string.h>
class IndiaBix
{
public:
void GetData(char *s, int x, int y )
{
int i = 0;
for (i = x-1; y>0; i++)
{
cout<< s[i];
y--;
}
}
};
int main()
{
IndiaBix objBix;
objBix.GetData((char*)"Welcome!", 1, 3);
return 0;
}
Discussion:
5 comments Page 1 of 1.
Satheesh said:
1 decade ago
s is type casted to array of characters ((char*)welcome!) and assigned welcome! to it. And using for loop first three characters are displayed.
Sanjay said:
10 years ago
I need more explanation.
Priyanka said:
10 years ago
Can anyone explain in brief?
Umar said:
10 years ago
In this prog *s is a string i.e welcome.
X=1
Y=3
Substitute in for loop
i=0,y>0,i++
s[0]=W;
Now i=1,y=2;
s[1]=e;
Now i=2,y=1.
s[2]=l;
Now i=3 and y=0.
Noe the loop will terminate so the o/p is well.
X=1
Y=3
Substitute in for loop
i=0,y>0,i++
s[0]=W;
Now i=1,y=2;
s[1]=e;
Now i=2,y=1.
s[2]=l;
Now i=3 and y=0.
Noe the loop will terminate so the o/p is well.
Sia said:
9 years ago
Hello friends, I can't understand this. Can you explain properly?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers