What is the sizeof char *.

28 Dec 2022 Balmiki Mandal 0 C Programming

Understanding the sizeof char * in Programming

The sizeof operator returns the size of a type in bytes. The type char * is a pointer to a character. The size of a pointer depends on the architecture of the machine, but it is typically 4 bytes on 32-bit machines and 8 bytes on 64-bit machines.

Therefore, the sizeof char * is typically 4 or 8 bytes, depending on the machine architecture.

Write a c program to exact size of a pointer on your machine

C- Programming
#include <stdio.h>

int main() {
  printf("%zu\n", sizeof(char *));
  return 0;
}

This code will print the size of a pointer in bytes to the console.

 

It is important to note that the sizeof operator returns the size of the type itself, not the size of the object that the pointer points to. For example, if a pointer points to an array of characters, the sizeof operator will return the size of the pointer, not the size of the array.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.