Output of C Programs | Set 14 Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 41 Likes Like Report Predict the output of below C programs. Question 1 C #include<stdio.h> int main() { int a; char *x; x = (char *) &a; a = 512; x[0] = 1; x[1] = 2; printf("%d\n",a); getchar(); return 0; } Answer: The output is dependent on endianness of a machine. Output is 513 in a little endian machine and 258 in a big endian machine.Let integers are stored using 16 bits. In a little endian machine, when we do x[0] = 1 and x[1] = 2, the number a is changed to 00000001 00000010 which is representation of 513 in a little endian machine. The output would be same for 32 bit numbers also.In a big endian machine, when we do x[0] = 1 and x[1] = 2, the number is changed to 00000001 00000010 which is representation of 258 in a big endian machine.Question 2 C int main() { int f = 0, g = 1; int i; for(i = 0; i < 15; i++) { printf("%d \n", f); f = f + g; g = f - g; } getchar(); return 0; } Answer: The function prints first 15 Fibonacci Numbers.Question 3 Explain functionality of following function. C int func(int i) { if(i%2) return (i++); else return func(func(i-1)); } Answer: If n is odd then returns n, else returns (n-1). So if n is 12 then we get 11 and if n is 11 then we get 11. Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above. Comment K kartik Follow 41 Improve K kartik Follow 41 Improve Article Tags : C Language C-Output Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like