C PROGRAM
The following is code prints the current activation record number, the memory address of the current array, followed by the estimated size of the current activation record as a distance between the current array address and the array address from the previous activation record. I need it to run until a segmentation fault occurs and also it must print the estimated size of the runtime stack as a product of the size of current activation record and the total count of activation records so far.
(Please help if you can)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000
void f1(){
char values[SIZE];
static int n = 0;
long int addr = (long int )&values[0];
static int i=0;
n++;
i++;
printf("Call #%d",n);
addr = (long int )&values[n];
printf(" at %p\n",addr);
printf("AR size #%d",n);
printf(" is : %d\n",((long int)&values[n] - (long
int)&values[n-1]));
}
void main()
{
for (int i=0; i<=10; i++)
{
f1();
}
for (int i=0; i<=100000; i++)
{
f2();
}
}
include <stdio.h>
#include <stdlib.h>
#define SIZE 1000
void f1()
{
int x;
char values[SIZE];
static int n=0;
values[n]=n;
char *addr;
static int i=0;
addr=&values[n];
n++;
i++;
printf("Call #%d",n);
addr = &values[n];
printf(" at %p\n",addr);
printf("AR size #%d",n);
printf(" is : %p\n",(&values[n]-&values[n-1]));
x=sizeof(addr)*n;
printf("Estimated Size of Runtime stack :%d\n",x);
}
void main()
{
for (int i=0; i<=100000; i++)
{
f1();
}
}
/*Segmentation fault occurs when we try to access that part of the memory which is not accessible to us and is allowed for reading purpose only.
So what i did above is i filled whole array with the values of n and when it becomes full we tried to access that part of memory which is not accessible to us because we declared size of array 1000 so this much memory is accessible to us and trying to access more will result in segmentation fault(core dump).*/
C PROGRAM The following is code prints the current activation record number, the memory address of...
Programming language question ( please help if you can ) write a function f1() with the following requirements (in C language): - It must define a local array of char values. The size must be adjustable via define macro. The default size could be, say, 1000. - It must also define a static int n that increments the number of activation records. - It must also define a static long int addr that stores the starting address of the array....
Consider the following code. Assume that the array begins at memory address Ox200. What is printed by the following code. Assume sizeof(int) is 4 bytes and sizeof(char) is 1 byte. Do not include the Ox or leading zeros in your answer. Enter -1 if the answer is indeterminate, or -2 if the code generates a compile error, or -3 if the code generates a runtime error. #include <stdio.h> int main() { int a[] {1,2,3}; int *iptr a; printf("%p\n", iptr+1); return...
Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h> #include <stdlib.h> #define SIZE 5 void displayData(int [], int s); void getData(int array[], int size) { for(int i=0; i<SIZE; i++) { scanf("%d", &array[i]); } } int main() { int grades[SIZE]; for(int i=0; i<SIZE; i++) { grades[i] = 0; } getData(grades,SIZE); displayData(grades, SIZE); } void displayData(int grades[], int size) { for(int i=0; i<size;...
I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...
I am writing a program that reads ten integers from standard input, and determines if they are going up or down or neither. Can I get some help? I have supplied what I have already. #include <stdio.h> #include <string.h> #include <stdlib.h> int isGoingUp(int [a]); int isGoingDown(int [b]); int main(void) { int array[10]; printf("Enter ten integers : "); for (int a = 0; a < 10; a++) scanf("%d", &array[a]); if (isGoingUp(array) == 1) printf("The values are going up\n"); else if (isGoingDown(array)...
I need the pseudocode for this c program source code. #include<stdio.h> void printarray(int array[], int asize){ int i; for(i = 0; i < asize;i++) printf("%d", array[i]); printf("\n"); } int sum(int array[], int asize){ int result = 0; int i = 0; for(i=0;i < asize;i++){ result = result + array[i]; } return result; } int swap( int* pA,int*pB){ int result = 0; if(*pA > pB){ int tamp = *pA; *pA = *pB; *pB = tamp; result = 1; } return result;...
OPERATING SYSTWM
Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...
The program is done in C. This program opens a file containing binary or text and reads every byte in the file and writes both the ASCII hex value for that byte as well as it’s printable (human-readable) character (characters, digits, symbols) to standard output. The issue I am having is when the file has multiple lines being read. The first line is read and done properly but the other lines do not work correctly. For instance, the text file...
P1) Write a complete C program that prints out the word YES, if its string command line argument contains the sequence the somewhere in it. It prints out the word NO otherwise. Both the word the and partial sequences like in the words theatre or brother qualify. Note: You can use string functions or not but if you do the only ones allowed are strcpy and strlen. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P2) What is the output of the following program (one answer per...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...