1) Consider the array declaration, int x[20];. There is no memory allocated for
ID: 3919308 • Letter: 1
Question
1) Consider the array declaration, int x[20];. There is no memory allocated for x[20].
2) Given the two C++ array declarations:
int a[10], b[10];
You can successfully compute one array, say a, then assign b to a:
a = b;
3) Give the syntax of an array declaration. Mention the base type and declared size.
4) The dot operator is used between an object and a data member or between a calling object and a call to a member function from the class of the object.
5) You can change the behavior of + for the int type using operator overloading
Explanation / Answer
/////////////////////////////////////////////////////////////////////////////////
Soution 1:
The given statement is false because whenever we declare any array with its size or statically it will automatically gets memory .
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Solution 2:
#include <iostream>
using namespace std;
int main()
{
int a[10],b[10];
int i;
//Values assign to array a
cout<<"Enter the values of Array a ";
for( i=0;i<10;i++)
{
cin>>a[i];
}
//Values assign to array b
cout<<" Enter the values of Array b ";
for( i=0;i<10;i++)
{
cin>>b[i];
}
//Printing values
cout<<" Printing array a";
for(i=0;i<10;i++)
{
cout<<a[i]<<" ";
}
cout<<" Printing array b";
for(i=0;i<10;i++)
{
cout<<b[i]<<" ";
}
//copying values of b to a array
for(i=0;i<10;i++)
{
a[i]=b[i];
}
cout<<" After copying the new 'a array': ";
for(i=0;i<10;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
Output:
Enter the values of Array a 1 2 3 4 5 6 7 8 9 10
Enter the values of Array b 11 22 33 44 55 66 77 88 99 01
Printing array a 1 2 3 4 5 6 7 8 9 10
Printing array b 11 22 33 44 55 66 77 88 99 01
After copying the new 'a array':11 22 33 44 55 66 77 88 99 01
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Soution 3:
Array declaeation is:
float arr[10];
here base type is float and size of array is 10.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Solution 4:
Yes, the dot operator is used between an object and a data member or between a calling object and a call to a member function from the class of the object. Example:
#include <iostream>
using namespace std;
class Test
{
private:
int int_num;
float float_num;
public:
int test_num=100;
void insertIntegerData(int d)
{
int_num =d;
cout << " Number: " << int_num;
}
float insertFloatData()
{
cout << " Enter float number: ";
cin >> float_num;
return float_num;
}
};
int main()
{
Test obj; //object of test class
float float_data;
cout<<" Value of test_num is : "<<obj.test_num; //calling data member of test class using object
obj.insertIntegerData(12); //calling function of test class using object
float_data = obj.insertFloatData();//assign value using object
cout << " You entered : " << float_data;
return 0;
}
Output:
Value of test_num is : 100
Number: 12
Enter float number: 56.7
You entered : 56.7
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Solution 5:
No, we can not change the behavior of + for the int type using operator overoading. When we perform operator overloading on any operator at least one of the arguments to the operator must be of a class type.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.