Bu örnekte, sizeof operatörünü kullanarak her bir değişkenin boyutunu bulmayı öğreneceksiniz.
Sizeof (değişken) operatörü, bir değişkenin boyutunu hesaplar. Ve sizeof tarafından döndürülen sonucu yazdırmak için %lu veya %zu biçim belirleyicisini kullanırız.
C Kodları:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<stdio.h> int main() { int intType; float floatType; double doubleType; char charType; // sizeof evaluates the size of a variable printf("int: %zu byte\n", sizeof(intType)); printf("float: %zu byte\n", sizeof(floatType)); printf("double: %zu byte\n", sizeof(doubleType)); printf("char: %zu byte\n", sizeof(charType)); return 0; } |
Ekran Çıktısı:
1 2 3 4 5 6 | int: 4 byte float: 4 byte double: 8 byte char: 1 byte |
Yorum Yap