Question

In: Computer Science

Modify the following code to use 'envp' instead of 'environ'. Be sure that you understand how...

Modify the following code to use 'envp' instead of 'environ'. Be sure that you understand how the code works. Provide liberal comments to explain what your pointer arithmetic is computing. Also, answer the following questions and explain your answers:

i) WHERE in process memory is it most likely that each of the values exist at run time?

ii) WHERE in process memory is it most likely the actual strings containing environment variables are stored?

#include
#include

extern char **environ; // look into what “extern” means when applied to
// a C global variable :)


int main(int argc, char **argv)
{ char **env_variable_ptr;

env_variable_ptr = environ;

while (*env_variable_ptr != NULL)
{ printf("%s\n", *env_variable_ptr);
env_variable_ptr++;
}

printf("\n");

}

Solutions

Expert Solution

1) The programming languages like C and C++, its static and dynamic memory allocation. All memory waas allocated during compile time.

C/C++ code to mashine output an executable file allocated in a compile file, memory always allocated in the RAM with the virtual memory.

The memory allocation at run/ compile-time resolves at the inside process of memory map

consider a global array variable.

int array [100];

Its compile-time the size of the array and the size of an int, its static storage global variable is allocated in static memory area of process memory.

Value initialized static storage.

int array[] = { 1,2,3,4,5 }

2) It consider memory segment data,heap,stack,and code, is allocated space by globle variable ,static variable get storage in memory.

1.global variable .. // data

2. static variables... // data

3. constant data type...// Its code and /or data, as string constant itself can be stored in the data sagment.

4. local variables... // stack

5. pointers... // ie *arr,int // It has heap data or stack,as declare a global or static pointer.

6. dynamically allocation ....// Its space using stack heap ( malloc,calloc,or realloc).


Related Solutions

Modify the classes so that it accepts integers instead of characters. (If you understand the concept...
Modify the classes so that it accepts integers instead of characters. (If you understand the concept of generic classes, convert the Node and Linked List classes to a generic so that they can be instantiated with either integers or characters) JAVA Code class aNode { char data; aNode next; aNode(char mydata) { // Constructor data = mydata; next = null; } }; //----------------------------------------------------- class linkedList { aNode head; // Head of the linked list int size; linkedList() { // Constructor...
Need to modify the below code to return the time in minutes instead of seconds. (Using...
Need to modify the below code to return the time in minutes instead of seconds. (Using Python 2.7.6 ) def numberPossiblePasswords(numDigits, numPossiblePerDigit):     numPasswords = numPossiblePerDigit**numDigits     return numPasswords def maxSecondsToCrack(numPossiblePasswords, secPerAttempt):     time = numPossiblePasswords*secPerAttempt     return time nd = int(input("How many digits long is the passcode? "))       nc = int(input("How many possible characters are there per digit? ")) secondsPerAttempt = .08 npp = numberPossiblePasswords(nd, nc) totalSeconds = maxSecondsToCrack(npp, secondsPerAttempt) print("It will take you " + str(totalSeconds) + "...
If there are 32 concurrent processes, how will you modify the following code? Process i do...
If there are 32 concurrent processes, how will you modify the following code? Process i do { while (turn == j);                critical section; turn = j;                remainder section } while (true);
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops...
Modify the following code to use ONLY pointer arithmetic (no array expressions) and no for loops to do the same thing this code does. Be sure that you understand how the code works and how the pointer arithmetic relates to the array expression form. Provide liberal comments to explain what your pointer arithmetic is computing. #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { int arg_count = 0; for (arg_count = 0; arg_count < argc; arg_count++) printf("%s\n", argv[arg_count]); }
Modify the following java code, utilizing a loop mechanism to enable the user to use the...
Modify the following java code, utilizing a loop mechanism to enable the user to use the calculator more than once. The program does the following:    It prompts the user to enter 2 numbers.    It prompts the user to choose an operation to perform on those numbers:    Operation 1: Addition.    Operation 2: Subtraction.    Operation 3: Multiplication.    Operation 4: Division.    It outputs the result of the operation.    It asks the user if they want...
I have to modify the following code to: 1. Use the unique algorithm to reduce the...
I have to modify the following code to: 1. Use the unique algorithm to reduce the array to unique values 2. Use the copy algorithm to display the unique results. #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() {     //creating an array of 20 integers     int array[20];     //creating an empty vector     vector<int> vec;     //input from end user to get 20 ints and a for loop to interate through 20     cout << "Enter 20 integers:"...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
Please read and understand the following program code. Use it to answer the following 4 questions....
Please read and understand the following program code. Use it to answer the following 4 questions. #include <iostream> #include <string> #include <sstream> using namespace std; class timeStamp // uses 24-hour times (0..24) { public:     timeStamp(void);     timeStamp(int, int, int);     void setTime(int, int, int);     timeStamp *addTimes(timeStamp *);     timeStamp *subTimes(timeStamp *);     string toString(void);     int hour;     int minute;     int second; }; int main() {     timeStamp noon(12, 0, 0);     timeStamp *teaTime = new timeStamp(51,...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire assignment. There are no more directions to it. Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make...
A major element of this week's lesson is making sure that you understand how the so-called...
A major element of this week's lesson is making sure that you understand how the so-called accrual adjustments "correct" a cash-basis income statement. For this discussion you need to select ONE (1) real-world example of a business circumstance that would reasonably be the basis for an accrual adjustment in an income statement. Be sure to (a) briefly describe that circumstance, (b) describe what the appropriate adjustment to the cash basis income statement such that it would then represent an accrual...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT