Please can you help me with my C++ Programming test True/False 1. A function is
ID: 3694036 • Letter: P
Question
Please can you help me with my C++ Programming test
True/False
1. A function is a program module that performs a specific well defined task.
2. A function can have zero or more arguments as input and zero or more return value.
3. We can use one for loop to process a two dimensional arrays.
4. An expression that evaluates to an integer can be used as an array subscript.
5. Arrays may not contain pointers.
6. A pointer to a function is the address where the code for the function resides.
7. A function can have a structure as an argument.
8. A function can return a structure.
9. A string that is a character pointer, can not be a function argument.
10. A function can return a pointer.
Short essay questions:
1. Why should you avoid using global variables?
2. Declare a pointer and an array size 5 type double and assign the address of the array to the pointer.
3. Use an example to show how you use the indirection operator.
4. What is a string? Define and provide an example
Using the following declarations.
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int *arr_ptr = arr;
What is the value of each of the following expressions?
*(arr_ptr + 4)
B) *arr_ptr + 4
arr_ptr[4]
(*arr_ptr)++
*(arr_ptr)++
Write a complete C++ program using the following specifications: ( )
In function main declare 2 variables type integer named num1 and num2. Ask the user to enter 2 integer numbers into num1 and num2.
Pass the address of num1 and num2 to a function named Multi ( ). Pass by reference.
The function Multi ( ) should multiply num1 by 5 and num2 by 10. For example if num1 was 5 and num2 was 10 before calling function Multi ( ) after function Multi( ) finished execution value num1 must be 25 and value num2 must be 100.
*(arr_ptr + 4)
B) *arr_ptr + 4
arr_ptr[4]
(*arr_ptr)++
*(arr_ptr)++
Write a complete C++ program using the following specifications: ( )
In function main declare 2 variables type integer named num1 and num2. Ask the user to enter 2 integer numbers into num1 and num2.
Pass the address of num1 and num2 to a function named Multi ( ). Pass by reference.
The function Multi ( ) should multiply num1 by 5 and num2 by 10. For example if num1 was 5 and num2 was 10 before calling function Multi ( ) after function Multi( ) finished execution value num1 must be 25 and value num2 must be 100.
Explanation / Answer
True or false questions answers:
Short essay questions.
Ans:-
int *ptr;
declaration of arrya of size 5 of type double
double ar[5]={10.125,20.125,30.125,40.125,50.125};
assigning the base address of the array to the pointer is
ptr=ar;
then by increasing the pointer we will get the next address of the array varible then using it we
can manipulate array.
3.
Example of indirection operator.
#include<stdio.h>
main()
{
int I;
int *p;
i=5;
p=&i; / * now *p==i */
printf(“i=%d, p=%u, *p =%d ”,i,p,*p);
*p=6;
printf(“i=%d,p=%u,*p=%d ,i,p,*p);
return 0;
}
After p points to i(p=&i), you can print i or *p and get the same thing. You can even assign to *p,
And the result is the same as if you had assigned to i.
4.
String:-
A string is a collection of characters or group of characters generally refer to any noun.
Declaring a stirng
Ex:-
char name[]=”bharath”;
int i=0;
while(i<7)
{
printf(“%c”,name[i]);
i++;
}
Or
char name[]=”bharath”;
char *ptr;
prt=name;
while(*ptr!=’’)
{
printf(“%c”,*ptr);
ptr++;
}
5.
*(arr_ptr + 4) value is 5;
*arr_ptr + 4value is 5;
arr_ptr[4]value is 5;
(*arr_ptr)++ value is 1;
*(arr_ptr)++ value is 1;
6.Program
void main()
{
int num1=0,num2=0;
clrscr();
printf(“ Enter two values for…. “);
scanf(“%d %d”,&num1,&num2);
printf(“values before fun cal is …. Num1 is %dnum2 is %d”,num1,num2);
multiply(&num1,&num2);
printf(“values after fun cal is …. Num1 is %dnum2 is %d”,num1,num2);
}
multiply(int *n1,int *n2)
{
*n1=(*n1)*5;
*n2=(*n2)*10;
}