Answer:
The valid operations are:
*q = *(&a[0]); and q = &(*p);
Explanation:
Given
The above declarations
Required
The valid operations
*q = *(&a[0]); and q = &(*p); are valid assignment operations.
However, q = &&a[0]; q = &&a; are invalid because:
The assignment operations intend to implicitly cast the char array a to pointer q. C++ does not allow such operation.
<em>Hence, *q = *(&a[0]); and q = &(*p); are valid</em>
Another way to know the valid operations is to run the program and look out for the syntax errors thrown by the C++ compiler
Answer:
Following are the program to this question:
#include <iostream> //defining header file
using namespace std;
int hailstoneLength(int n) //defining method hailstoneLength
{
int t=1; //defining integer variable assign
while(n!=1) //define a loop that checks value is not equal to 1
{
if(n%2==0) // check even number condition
{
n=n/2; // divide the value by 2 and store its remainder value in n
t++; //increment value of t by 1.
}
else
{
n=n*3+1; //calculate and hold value in n
t++; //increment value of t variable by 1
}
}
return t; //return value
}
int main() //defining main method
{
int n; //defining integer variable
cout<<"Enter any number: "; //print message
cin>> n; //input value
cout<<hailstoneLength(n); //call method and print its value
return 0;
}
Output:
Enter any number: 3
8
Explanation:
Program description can be given as follows:
- In the given C++ language program an integer method "hailstoneLength", is declared, that accepts an integer variable "n" in its parameter.
- Inside the method, an integer variable t is declared, that assign a value that is 1, in the next line, a while loop is declared, that uses if block to check even condition if number is even it divide by 2 and increment t variable value by 1.
- If the number is odd it will multiply the value by 3 and add 1 and increment t by 1 then it will go to if block to check value again. when value of n is not equal to 1 it will return t variable value.
- In the main method, an integer variable "n" is used that call the method and print its return value.
Answer:
two rows, three columns, table width of half the screen, and a thin border
Explanation:
The code given in the image is HTML code that is used to generate a table.
Each Starting row tag generate a row and each column tag generate the column.
so in given code
<tr>
</tr>
is used to generate a row.
Then
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<em>This portion of the code generate one row and three columns of table. As this section repeats two times, it means that 2 rows and 3 columns will be generated.</em>
<table width="50%" border="1">
<em>this code used to generate the table of half of the screen and thin border.</em>
<em></em>