Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Is it possible to get help with this c programming questions? Is it possible to

ID: 3709278 • Letter: I

Question

Is it possible to get help with this c programming questions? Is it possible to get help with this c programming questions? Consider the following program: #include int main(void) t ong arr[10115 printf("arr %pn", arr) ; printi"arr[1] : %pm", arr(11) ; return 0 Note: int data type takes four bytes If the array is stored at Oxbffff8bc, which one of the following options is the output of the program? Options a) arr Oxbfff8bo b) arr 0xbfff8bo c) arr Oxbfff8bo d) arr Oxbfff8bo arr1] 0xbffff8df arrí1] 0xbfff8dc arrt1] 0xbfff8do arri1] Oxbfff8d4 e) None of the above 30) Assuming that the file my.bin is a binary file whose size if 1024 bytes. What will be the size of the file after the function foo('my bin", 3) is called int foo(char "filename, int num) int rc 0: FILE "fp if (filename NULL) return(1) (fpNULL) return( 1) rc fwrite(#, sizeof (int), 1, fp): fclose(fp) if (rc 1) return(1) return(0) Options b) 4 c) 1024 d) 1028 e) None of the above

Explanation / Answer

29 Q):

Answer: = 0xbffff8d0

In C, different architectures take different sizes for int and long.

I have tested my application in Windows, it gave me - Size of (int) = 4 , Size of (long) = 4

In other linux machine I tested it, it gave me - Sizeof(int) = 4 , Sizeof(long) = 8

Here long Arr[10][5], a 2D array.   i.e.   10 rows, 5 columns.

Arr = Arr[0] = Arr[0][0] points to the first row,   Arr[1]= Arr[1][0] points to the second row. (This is logical representation.)

But, in memory, They are stored in continuously.

Let Assume, size of long as 4 bytes.    

Long 1

Long 2

Long 3

Long 4

Long 5

Long 6

Long 7

Long 8

Long 9

Long 10

Arr[0]

Arr[1]

Arr[0]=Arr[0][0] ,        Arr[1]= Arr[1][0]

There is a difference of 5 long values. Each long takes 4 bytes i.e. 5 x 4 = 20 bytes diffence

Convert 20 bytes to hexa decimal = 0x14

Arr / Arr[0] stored at 0xbffff8bc

Arr[1] stored at   :   0xbffff8bc + 0x14 (hexa decimal addition) = 0xbffff8d0

If we assume long as 8 bytes, then 8x5 = 40 bytes = 0x28 (hexa) and if we add this value to 0xbffff8bc then it is 0xbffff8e4, which is not present in options given in answers.

#include <stdio.h>

int main(void) {

      long arr[10][5];

      printf("Size of Int : %p ", sizeof(int));

      printf("Size of long : %p ", sizeof(long));

      printf("arr = %p ", arr);

      printf("arr[0] = %p ", arr[0]);

      printf("arr[1] = %p ", arr[1]);

      return 0;

}

Output:

Size of Int : 00000004

Size of long : 00000004

arr = 0061FE68

arr[0] = 0061FE68

arr[1] = 0061FE7C

30 Q)

Answer;:   4 bytes

The file is opened in wb+ mode,  

W+     for   reading and writing. It will Create or Overwrite existing file.   b à is for opening in binary mode.

So, the file is emptied after opening the file.

Int type takes 4 bytes. So, we are writing a num (int type) in file. So, the file size will be 4 bytes.

Sample Output:   ( I have tested the size of the file before and after writing).

The size of given file is : 1024

The size of given file is : 4

31Q)

Answer: 1000

The function multiply the given number (x) , n number of times.

You can see the stack calling in sample output.

When n=0 it returns 1, so the values replaced in the stack and get the output of 1000.

Mystery(10,0) returns 1. This value replace in the stack and we will get this answer.

i.e.     1 * 10 * 10 * 10 = 1000

Sample Output for the program:

Calling mystery(10,3)

Calling: mystery(10, 2)*10

Calling: mystery(10, 1)*10

Calling: mystery(10, 0)*10

Returning 1

Mystery : 1000

32Q)

Answer:    aello OK

Program: (Step by step analysis)

struct data x,y;    // 2 structure variables

      x.str = (char *) malloc(6); // Allocating memory for *str

      if (x.str == null) return 1; // If memory not allocated, return

      strcpy(x.str, "Hello"); // Hello string is copied to x.str

      strcpy(x.a, "OK");    //   OK is copied to x.a

     

      y=x; // Copying the data to structure y

      Here, the contents of the “char array” (x.a[3]) are copied to y.a[3] and x.str pointer value (address) is copied to y.str pointer (address). So, they point to the same string (same memory location). So, editing the contents of string using x.str pointer, will reflect the contents of y.str

     

x.str[0]='a';   // So, contents of y.str[0] will also get modified.

      x.a[1]= '!';    // Here only contents of x.a[1] are modified. Not y.a[1].

     

      printf("%s %s ", y.str, y.a); So output:   aello OK

33Q)

Ans: None of the Above

      main(int argc, char *argv[])

      argc à Contains the number of arguments passed to the program, including the name of the program.

So, we pass one argument, then the value of argc = 2

If we don’t pass any argument, then value of argc = 1 (the c program name)

      *argv[] -> character pointer pointing to the array of arguments passed, including program name.

i.e. argv[0] contains the char string = program name

argv[1] contains first argument if passed.

So, all the options are wrong.

Long 1

Long 2

Long 3

Long 4

Long 5

Long 6

Long 7

Long 8

Long 9

Long 10

Arr[0]

Arr[1]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote