עובדות מעניינות בתכנות C
להלן כמה עובדות מעניינות על תכנות C:
1)
תוויות האותיות של משפט switch יכולות להופיע בתוך הצהרות if-else.
C #include int main () { int a = 2 b = 2 ; switch ( a ) { case 1 : ; if ( b == 5 ) { case 2 : printf ( 'GeeksforGeeks' ); } else case 3 : { } } }
פלט:
GeeksforGeeks2)
arr[index] זהה לאינדקס[arr] הסיבה לכך היא שהגישה לרכיבי מערך היא באמצעות אריתמטיקה מצביע.
C// C program to demonstrate that arr[0] and // 0[arr] #includeint main () { int arr [ 10 ]; arr [ 0 ] = 1 ; printf ( '%d' 0 [ arr ] ); return 0 ; } פלט:
13)
אנחנו יכולים להשתמש ב' <: :>' במקום '[]' ו-' <% %>' במקום '{}'
C#includeint main () <% int arr <: 10 :> ; arr <: 0 :> = 1 ; printf ( '%d' arr <: 0 :> ); return 0 ; %> פלט:
14)
שימוש ב-#include במקומות מוזרים. תן 'a.txt' להכיל ('GeeksforGeeks');
CPP#includeint main () { printf #include 'a.txt' ; } פלט:
GeeksforGeeks5)
אנו יכולים להתעלם מקלט ב-scanf() באמצעות '*' אחרי '%' במפרטי הפורמט
Cצור חידון#includeint main () { int a ; // Let we input 10 20 we get output as 20 // (First input is ignored) // If we remove * from below line we get 10. scanf ( '%*d%d' & a ); printf ( '%d ' a ); return 0 ; }