C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 30)
30.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<string.h>
#include<malloc.h>
class BixString
{
char txtName[20];
public:
BixString(char *txtTemp = NULL)
{
if(txtTemp != NULL)
strcpy(txtName, txtTemp);
}
void Display(void)
{
cout<<txtName;
}
};
int main()
{
char *txtName = (char*)malloc(10);
strcpy(txtName, "IndiaBIX");
*txtName = 48;
BixString objTemp(txtName);
cout<< sizeof(txtName);
return 0;
}
Discussion:
18 comments Page 2 of 2.
Vamshi said:
7 years ago
The main thing *txtName = 48; was replace the first char with 48 which means zero('0') now malloc allocate "0ndiaBIX" now size is 9.
Prabha said:
1 decade ago
The answer is coming out to be 4 which is the size of integer. So correct answer should be option C.
Confidante said:
1 decade ago
The output is coming as 4 only. cout<<sizeof(xx) displays the size of integer only.
Ashish kshatriya said:
9 years ago
The correct answer will be 4 which is size of int, so it is option C.
Priya said:
1 decade ago
How indiabix will be printed? They are not calling display function.
Ozlemsen said:
1 decade ago
Agree with @Aakash:
The answer is 4. And it's the size of pointer.
The answer is 4. And it's the size of pointer.
Sadik Khan said:
8 years ago
The correct answer is 4 size of pointer.
Neha said:
7 years ago
According to me, The output is 4.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers