Write a function that takes a character string value and prints out the bytes stored in memory of its representation (including the terminating 0). Test it on a string containing your full name.

Respuesta :

Answer:

C++ code explained below

Explanation:

SOURCE CODE:

*Please follow the comments to better understand the code.

#include <stdio.h>

int numOfBytes(char* string)

{

// initialise the variables

int i=0,size=0;

// while the string reaches to \0, repeat the loop.

while(string[i]!='\0')

{

// add that size

size += sizeof(*string);

 

// increase the i value.

i++;

}

// add 1 byte for \0

size = size+1;

return size;

}

int main() {

char name[]="Praveen Kumar Reddy";

printf("The size is %d bytes.",numOfBytes(name));

 

  return 0;

}

=============