Question

1. Typically, arrays are passed by reference in programming languages since they can be arbitrarily long and copying each element may take time and space. How are arrays passed to functions in C++? If by reference, is there a way to pass them by value? If so, how? Show coded examples and output.

2. Can separate blocks be specified in C++, and if so, how is variable scoping handled? Show coded examples and output. For example:

int main() // declare variables { // declare variables (maybe also with same name as above) // and so on... for (...) // make

3. Can the goto statement be utilized in C++? If so, what do you go to? Show coded examples and output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:
Yes when we wrap the array inside the structure than we can pass array as call by value

struct ArrayStruct
{
int arr[10];
};
  
void change(struct ArrayStruct temp)
{
int *ptr = temp.arr;
int i;
  
for (i = 0; i < 10; ++i)
ptr[i] = 100; // OR *(ptr + i)
  
}
  
int main()
{
int i;
struct ArrayStruct obj;
for (i=0; i<10; i++)
obj.arr[i] = 10;
  
for (i = 0; i < SIZE; ++i)
cout<<obj.arr[i]<<" ";
cout<<endl;
  
change(obj);
  
  
  
for (i = 0; i < SIZE; ++i)
cout<<obj.arr[i]<<" ";
  
return 0;
}

Answer 2:
Yah we can have different blocks in cpp
So the variables created inside the block will accessable inside the block and to its child blocks
int main(){
   int x=1;
   {
       int x=2;
       cout<<<x<<endl; // 2 will print
       {
           cout<<x<<endl; // 2 will print
       }
   }
   cout<<x<<endl; // 1 will print
}

Answer 3:
we can use goto in cpp to jump the control from one location to another location
int main(){
   int x=10;
   PRINT:
   cout<<x<<endl;
   x--;
   if x>10:
       goto PRINT;
      
}

Add a comment
Know the answer?
Add Answer to:
1. Typically, arrays are passed by reference in programming languages since they can be arbitrarily long...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program Overview This brief exercise is designed for you to consider how reference variables behave when...

    Program Overview This brief exercise is designed for you to consider how reference variables behave when you are passing them as arguments by-value. Instructions Name your class References.java. 1. Implement the following methods. 1.1 Method name: readStudentNames Purpose: This method accepts an array of strings as a parameter. It loops through the array and asks the user to input names. It populates the array of strings with the names. Parameters: an array of Strings, stringArray Return type: void In the...

  • Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...

    Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • Keep identifiers to a reasonably short length. • Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). • Use tabs or spaces to indent code within blocks (code surrounded by braces)....

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • Hi, this is an intro to C Programming Class. Please do not use arrays, functions, math.h,...

    Hi, this is an intro to C Programming Class. Please do not use arrays, functions, math.h, or struct to store any data except to declare strings char strVar[20]. Furthermore, can you please do a good check to make sure the final program does not have any problems because when I copy and paste them the app I use says there are some problems and it won't run the program. So if you can double check to make sure that everything...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • A - Write pseudocode B - Write A PYTHON PROGRAM Driver’s License Exam The local driver’s...

    A - Write pseudocode B - Write A PYTHON PROGRAM Driver’s License Exam The local driver’s license office has asked you to design a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an array. (Store each question’s...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • Have you ever wanted to predict the future? Well the Magic Eight Ball does just that....

    Have you ever wanted to predict the future? Well the Magic Eight Ball does just that. The original game was a softball sized “8-ball”. You would ask a question, shake it up and look at the result. There are 20 responses…10 positive, 5 negative, and 5 are vague. For this project, we want to recreate this, but give the ability to read in a set of responses, and add additional responses, and print out all of the responses in alphabetical...

  • **JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Metho...

    **JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Methods Loops and Conditionals Description The goal of this assignment is for you to produce a simple procedurally generated terrain map out of ASCII character symbols. This will be done through simple probability distributions and arrays Use the following Guideline s: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. User upper case for constants....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT