In: Computer Science
Do in c++ programming languages
Question 1: Solve the complete Question with all parts and subparts.
a) What do you understand by the term DATA TYPE?
b) Is it possible to replace for loop with a while loop. Justify your answer with reasoning and example.
c) Draw a flow chart for Do-While loop for controlled/uncontrolled infinite loop iterations.
d) Write down a function prototype that takes an array and its length as an argument and also return the same array by reversing the position of elements.
e) As you know that “the base address or the starting address of any array is its name”. Keeping this information, answer
i) Why the first index of any array always starts from zero. Although it points to the first location of an array.
ii) The reason why the last index is always one less than array length is “the first index starts from zero”. Does it seems to be a correct reason justify.
iii) What is the offset address of any array NAMED AS ARR1 who starting address is A011234h.
iv) Can you find the offset address of the 6th element of array given in 3? If its data type is INT. 5. What is the offset address of last element of an array stated in 3? If the length of array is 5 and data type is char.
Note: If you are not able to do complete question with parts and its subparts so kindly never do any single part ( i need complete question with proper answers.
a)
Data type of any variable is a special type of attribute which lets the compiler or interpreter know what kind of data user will be storing in it.
eg - int,char,float,double
b)
In a for loop 3 steps take place (i) initiation -In this step a variable is assigned with initial value (ii) condition-After initiation, condition checking takes place so if condition satisfies (iii) Increment or decrement of variable takes place
So if we can implement all these three steps in while loop we can replace for loop with while loop
and we can do it actually
initializing the variable with initial value before while loop
inside while(condition) checks for condition and inside the body of loop increment or decrement takes place
eg-
for(int i=0;i<23;i++)
{
printf(4);
}
this code with while loop will be like
int i=0;
while(i<23)
{
printf(4);
i++;
}
int *reverse(int arr[],int
n)
{
int temp;
for(int i=0;i<=n/2;i++)
{
temp=arr[i];
arr[i]=arr[n-i-1];
arr[n-i-1]=temp;
}
return(arr);
}