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

Which is not a reason that pointers are valuable? Pointers allow for faster acce

ID: 3822167 • Letter: W

Question

Which is not a reason that pointers are valuable? Pointers allow for faster access to array elements. Pointers speed the process of passing objects like classes to functions. Pointers allow function to be passed as an argument to other functions. Pointers involve a great deal of overhead when used in conjunction with arguments. N-1 is the __________ first position of an array position of Row position of Column last position of an array When working with an array, the easiest way to traverse or visit array is to ___________. use a loop statement sort the array and read it do a binary search use sequential coding a Explain which is more appropriate for writing a menu program: a switch case or if-else statements. Provide a snippet of code to support your position. (TCO 7) In your own words, define a function and code an example of creating a function and calling it.

Explanation / Answer

Answers

5.Pointers involve a great deal of overhead when used in conjuction with arguments.

6. Last position of an array. //because array index starts from 0 to size -1.

7. Use a loop statement .//a loop can starting from 0 to size-1 can easily use to traverse

i.e for(int =0; i<size;i++) {

cout<<arr[i];

}

6. A switch case is more appropriate to use for menu driven program due to following reason:

if( condition-1)

    statement-1;

else if (condition-2)

    statement-2;

else if (condition-3)

    statement-3;

else if (condition-4)

    statement-4;

else if (condition-n)

    statement-n;

else

    default statement;

SWITCH CASE

switch(expression)

{

    case constant-1

        block-1;

        break;

    case constant-2

        block-2;

        break;

    case constant-3

        block-3;

        break;

    case constant-n

        block-n;    

        break;

    default:

        default_block;

}

4.(TCO 7) Function:

A function is a group of statements that together perform a task.for example a function to calcute simple interest, a function to print prime number , a function to print word count etc.

A function is being called whenever it is required just by calling its name, and it perform the task assigned to.

You can divide up your code into separate functions.for the madularity and ease.logically the division is such that each function performs a specific task.

A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.

Example :

#include<stdio.h>

// function prototype, also called function declaration

void swap(int *a, int *b);

int main()

{

    int m = 22, n = 44;

    //  calling swap function by reference

    printf("values before swap m = %d and n = %d",m,n);

    swap(&m, &n);        

}

void swap(int *a, int *b)

{

    int tmp;

    tmp = *a;

    *a = *b;

    *b = tmp;

    printf(" values after swap a = %d and b = %d", *a, *b);

}

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