What is the purpose of the ‘sizeof’ operator in C?

What is the purpose of the ‘sizeof’ operator in C?

a) To determine the size of a variable or data type
b) To allocate memory dynamically
c) To find the length of a string
d) To initialize an array

Answer:

a) To determine the size of a variable or data type

Explanation:

The sizeof operator in C is used to determine the size, in bytes, of a variable or data type. For example, sizeof(int) returns the number of bytes occupied by an integer on the system. This operator is useful for memory management, especially when working with arrays, structures, and dynamic memory allocation.

Understanding the sizeof operator is important for writing efficient C programs that make proper use of memory.

Reference links:

https://www.rameshfadatare.com/learn-c-programming/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top