Knowee
Questions
Features
Study Tools

What will be the output of the following C code?int main(){char *ptr1, *ptr2;printf("%d %d", sizeof(ptr1), sizeof(ptr2));return 0;} 4 4Undefined2 21 1

Question

What will be the output of the following C code?int main(){char *ptr1, *ptr2;printf("%d %d", sizeof(ptr1), sizeof(ptr2));return 0;} 4 4Undefined2 21 1

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given C code will be "4 4" or "8 8" depending on whether the code is being run on a 32-bit or 64-bit system. This is because the sizeof operator in C returns the size (in bytes) of the object or type. In this case, ptr1 and ptr2 are pointers, and the size of a pointer is either 4 bytes (on a 32-bit system) or 8 bytes (on a 64-bit system).

Similar Questions

What will be the output of the following C code? #include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%d\n", *ptr); }

What will be the output of the following code?12345678910#include <stdio.h> int main() { int x = 10; int *ptr1 = &x; int *ptr2 = ptr1; (*ptr2)++; printf("%d %d", *ptr1, *ptr2); return 0;}

What will be the output of the following code?int main() {    int *ptr = NULL;    ptr = (int*)malloc(sizeof(int));    *ptr = 5;    printf("%d\n", *ptr);    free(ptr);    return 0;}

What is the output of the following code?1234567891011#include <stdio.h>int main() { char c = 'K'; char* ptr = &c; (*ptr)++; printf("%c ", *ptr); (*ptr)--; printf("%c", *ptr); return 0;}

Which will be the output? #include<stdio.h> int main () { char i=65; printf (“%d”, sizeof(i)); return 0; } 4 8 2 1

1/3

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.