Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Are the following claims true or false? If false, please explain why and correct

ID: 3547538 • Letter: A

Question

Are the following claims true or false? If false, please explain why and correct it. Declaration int a[3] [4]; declares an array that contains 12 indexed variables, and their indices ranges from 0 to 12, that is, they are a[ ], a[1],-, a[7], a[8], a[11]. Declaration int a[][2]={{l,2},{3,4}}; declares a 2-dimensional array that contains 4 indexed variables. Suppose that int funl(int& x) is correctly defined, then the following statement Function declaration int funl(int x[][2]); is not correct, as formal parameter x[] [2] does not contain an integer within the first pair of brackets. Suppose that int funl(int x[][2])i is correctly defined, then the following statement C++ allocates 5 bytes for the following array The following three statements are equivalent. The following statements will display sane on screen, char a[]="Thanksgiving", b[]="Thanksgiving"; Arc the following statements correct if they are embedded in a program (assuming the rest of the program is correct)? Why or Why not? If correct, what will be the output of the following code? If not, how to correct any errors?

Explanation / Answer

// PROBLEM 1.
a) Declaration int a[3][4];
declares array that contain 12 indexed variables, and their indices ranges from 0 to 12. that is they are
a[0], a[1]......a[7],a[8]...a[11].

FALSE. a is two dimensional array with first dimension index ranges from 0 to 3 and
second dimension index ranges from 0 to 4.

b) Declaration int a[][2] = {{1,2},{3,4}};
declares two dimensional array that contain 4 indexed variables.

TRUE.

c) Suppose that int fun1(int& x) is correctly defined, then following statement.
int a[2][3];
cout << fun1(a[1][2]) << endl;
is accetable in C++;

TRUE.

d) Function declaration int fun1(int x[][2]);
is not correct as formal parameter x[][2] doesnt contain an integer with in first pair of brackets.

FALSE.. given syntax is correct and its allowed in C++.

e) Suppose that int fun1(int x[][2]) is correctly defined, then following statement.
int a[2][3];
cout << fun1(a[1][2]) << endl;
is accetable in C++;

FALSE. function expecting two-dimensional argument..but we are passing integer argument..which is not allowed in C++.

f) C++ allows 5 bytes for following array.
char c[] = "Hello";

false. C++ allows 6 bytes for above statement.

g) the following three statement are equal

char str1[] = "Hello";
char str1[] = {'H','e','l','l','0',''};
string str1 = "Hello";

TRUE.

h) the following statement will dispaly same on screen..
char a[] = "Thanksgiving"; char b[] = "Thanksgiving";
if(a==b)
cout << "same";
else
cout << "different";

FALSE.
we are not supposted to compare string in above fashion. we have to strcmp function.

#include<iostream>
using namespace std;
int main()
{
string str1,str2,str3;
str1="Hello";
cin >> str2;
str3 = str1+ str2+ " Happy Thanks giving";
cout << str1 << str2 << "+" <<str3 << endl;
return 0;
}

//above lines are perfectly valid in C++.
Hello+how+Hellohow Happy Thanks giving
// if we want to get entire line How are you ??
getline(cin,str2);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote