Answer to Question #283446 in C++ for nana coo

Question #283446

300-500 words per discussion and avoid plagiarism



discuss the following



a. pointers



b. arrays



c. structures



d. classes



e. functions


1
Expert's answer
2021-12-29T07:57:23-0500

Pointers-A pointer is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before you can work with it. The general form of a pointer variable declaration is type *var-name.Here, type is the pointer's base type; it must be a valid C++ type and var-name is the name of the pointer variable. The asterisk you used to declare a pointer is the same asterisk that you use for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.There are few important operations, which we will do with the pointers very frequently.

 (a) We define a pointer variable.

 (b) Assign the address of a variable to a pointer. 

(c) Finally access the value at the address available in the pointer variable.

Array-Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.

To declare an array, define the variable type, specify the name of the array followed by square brackets and specify the number of elements it should store:string bikes[4];We can use normal variables (v1, v2, v3, ..) when we have a small number of objects, but if we want to store a large number of instances, it becomes difficult to manage them with normal variables. The idea of an array is to represent many instances in one variable.

Structure- Structure is a collection of variables of different data types under a single name. It is similar to a class in that, both holds a collection of data of different data types.The ‘struct’ keyword is used to create a structure. The general syntax to create a structure is as shown below:  

struct structureName{ member1; member2; member3; . . . memberN; };

structure variable can either be declared with structure declaration or as a separate declaration like basic types.  

Classes-A class in C++ is the building block that leads to Object-Oriented programming. It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A C++ class is like a blueprint for an object.

A class is a user-defined data type that we can use in our program, and it works as an object constructor, or a "blueprint" for creating objects

The body of the class is defined inside the curly brackets and terminated by a semicolon at the end.

Functions-A function is a block of code which only runs when it is called.Functions are used to perform certain actions, and they are important for reusing code: Define the code once, and use it many times Declared functions are not executed immediately. They are "saved for later use", and will be executed later, when they are called.

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.

The C++ standard library provides numerous built-in functions that your program can call. For example, function strcat() to concatenate two strings, function memcpy() to copy one memory location to another location and many more functions


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog