C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 19)
19.
What will be the output of the following program?
#include<iostream.h>
#include<string.h>
class IndiaBix
{
char str[50];
char tmp[50];
public:
IndiaBix(char *s)
{
strcpy(str, s);
}
int BixFunction()
{
int i = 0, j = 0;
while(*(str + i))
{
if(*(str + i++) == ' ')
*(tmp + j++) = *(str + i);
}
*(tmp + j) = 0;
return strlen(tmp);
}
};
int main()
{
char txt[] = "Welcome to IndiaBix.com!";
IndiaBix objBix(txt);
cout<< objBix.BixFunction();
return 0;
}
Discussion:
9 comments Page 1 of 1.
Deepti said:
7 years ago
@All.
The code is;
if(*(str + i++) == ' ')
*(tmp + j++) = *(str + i);
counts the spaces i.e. ' ' in string str and stores the next character in temp as "tI\0"
1) t of to
2) I of India
and strlen returns length of tmp excluding null character.
i.e. 2.
The code is;
if(*(str + i++) == ' ')
*(tmp + j++) = *(str + i);
counts the spaces i.e. ' ' in string str and stores the next character in temp as "tI\0"
1) t of to
2) I of India
and strlen returns length of tmp excluding null character.
i.e. 2.
(1)
Suresh L said:
1 decade ago
The 2 spaces will be counted because the if condition satisfies only at the empty places.
Dixit said:
1 decade ago
tmp[0] = t.
tmp[1] = I.
tmp[2] = 0.
So length of tmp is 2.
tmp[1] = I.
tmp[2] = 0.
So length of tmp is 2.
(1)
Abhijith Musale said:
9 years ago
I'm also not understanding the program. Explain it.
Gayathry said:
9 years ago
Yes, I'm also not getting this please explain.
Akshay said:
7 years ago
Please, explain the program in detail.
Smsk said:
9 years ago
Please explain the program in detail.
Arti said:
7 years ago
Please explain it to me.
Bhavna said:
10 years ago
Not able to understand.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers