13. Choose the correct statement that is a combination of these two statements,Statement 1: char *p;Statement 2: p = (char*) malloc(100);1) char p = *malloc(100);2) char *p = (char*)malloc(100);3) char *p = (char) malloc(100);4) None of the above
Question
- Choose the correct statement that is a combination of these two statements,Statement 1: char p;Statement 2: p = (char) malloc(100);1) char p = *malloc(100);2) char p = (char)malloc(100);3) char *p = (char) malloc(100);4) None of the above
Solution
The correct statement that combines Statement 1: char p; and Statement 2: p = (char) malloc(100); is option 2) char p = (char)malloc(100);. This statement declares a pointer to a char and allocates memory of size 100 bytes, then assigns the address of the first byte of the allocated memory to the pointer.
Similar Questions
The right way to merge the below 2 statements is?char *ch;ch = (char*) malloc(100);a.char *ch = (char*)malloc(100);b.char *ch = (char) malloc(100);c.char ch = *malloc(100);d.char *ch = (char *)(malloc*)(100);
What will be the result of the following code snippet?int main() { int *ptr1, *ptr2; ptr1 = (int *)malloc(sizeof(int)); ptr2 = (int *)malloc(sizeof(int)); *ptr1 = 42; *ptr2 = *ptr1; free(ptr1); printf("%d\n", *ptr2); free(ptr2); return 0;}
Which of the following statements about pointers is true?
Mark statements as T/F.True False int *p, i;char *cp, c;p = &i;cp = (char *)p;cp[2] = 'x';The last line of the above code modifies the variable i int *p; double *dp;sizeof(p) is 4 bytes while sizeof(dp) is 8 bytes. int *p;p[1] means *(p + 1) int *p; double *dp;p = p + 1 advances p by sizeof(int) bytes
Multi Choice Type QuestionWhat does malloc function do in C?Marks : 1Negative Marks : 0Answer hereAllocates memory and initializes it to zeroAllocates memory without initializing itFrees allocated memoryReallocates memory
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.