I have a test coming up and need some help. Could you provide code -Type of a po
ID: 640923 • Letter: I
Question
I have a test coming up and need some help. Could you provide code
-Type of a pointer determines how the memory referred to by the pointer is used.
-An array pointer does not know how many elements its memory points to.
-A pointer is an alias to another existing object.
-A memory leak. How to get it? How to prevent it?
-A memory exhaustion. How to get it?
-Define and initialize a dynamic array.
-Changing the capacity of a vector when the number of elements in a vector is equal to its capacity.
-Declaration of a C-string.
-How to concatenate two C-strings?
-How to concatenate two STL strings?
-Examples of using a copy constructor and copy assignment for the vector class.
Functions
-Passing parameters to a function.
-How do the function calls work?
-Function overloading.
-How does the recursion work?
Explanation / Answer
A void pointer cannot be directly dereferenced because it is not pointing at a specific type
i dont know exactly for second one
when use call by referrence function then pointer acts as a alias
memory leak if try to store data more than size...to avoid use sentinel
memory exhaustion/stack overflow can be used as a form of denial of service attack
ptr=(int*)malloc(100*sizeof(int));
if (index + 1 > v.size()
{
if (v.capacity() < index + 1)
{
v.reserve(2 * (index + 1)); // I had 2 * capacity() here first, but
// I think this version is better
}
v.resize(index + 1);
}
String a ="hello world";
strcat(a,b)
passing parameters
#include <stdio.h>
int main( int argc, char *argv[] )
{
if( argc == 2 )
{
printf("The argument supplied is %s ", argv[1]);
}
else if( argc > 2 )
{
printf("Too many arguments supplied. ");
}
else
{
printf("One argument expected. ");
}
}
function call
first main function
next call function
pass parameters
return parameters to calling function
then function terminates
function overloading
Function overloading or method overloading is the ability to create multiple methods of the same name with different implementations.
Recursion is the process of repeating items in a self-similar way.
void recursion()
{
recursion(); /* function calls itself */
}
int main()
{
recursion();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.