#include<stdio.h> int reverse(int); int main() { int no=5; reverse(no); return 0; } int reverse(int no) { if(no == 0) return 0; else printf("%d,", no); reverse (no--); }
Step 2: reverse(no); becomes reverse(5); It calls the function reverse() with '5' as parameter.
The function reverse accept an integer number 5 and it returns '0'(zero) if(5 == 0) if the given number is '0'(zero) or else printf("%d,", no); it prints that number 5 and calls the function reverse(5);.
The function runs infinetely because the there is a post-decrement operator is used. It will not decrease the value of 'n' before calling the reverse() function. So, it calls reverse(5) infinitely.
Note: If we use pre-decrement operator like reverse(--n), then the output will be 5, 4, 3, 2, 1. Because before calling the function, it decrements the value of 'n'.
#include<stdio.h> const char *fun(); int main() { *fun() = 'A'; return 0; } const char *fun() { return "Hello"; }
#include<stdio.h> int main() { char s[] = "CuriousTab"; char t[25]; char *ps, *pt; ps = s; pt = t; while(*ps) *pt++ = *ps++; /* Add a statement here */ printf("%s\n", t); return 0; }
#include<stdio.h> float a=3.14; double b=3.14;
To print a double value, %lf is used as format specifier.
Therefore, the answer is printf("%f %lf", a, b);
#include <stdio.h>
int main(void)
{
char string[80];
printf("Enter a string:");
gets(string);
printf("The string input was: %s\n", string);
return 0;
}
Output:
Enter a string: CuriousTab
The string input was: CuriousTab
#include<stdio.h> int main() { int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u\n", arr, &arr); return 0; }
Step 2: printf("%u, %u\n", arr, &arr); Here,
The base address of the array is 65486.
=> arr, &arr is pointing to the base address of the array arr.
Hence the output of the program is 65486, 65486
#include<stdio.h> int main() { struct emp { char *n; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; strupr(e2.n); printf("%s\n", e1.n); return 0; }
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int num1 = 12345;
float num2 = 5.12;
char str1[20];
char str2[20];
itoa(num1, str1, 10); /* 10 radix value */
printf("integer = %d string = %s \n", num1, str1);
sprintf(str2, "%f", num2);
printf("float = %f string = %s", num2, str2);
return 0;
}
// Output:
// integer = 12345 string = 12345
// float = 5.120000 string = 5.120000
Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=> foo_bar
=> _foo42
=> _
=> QuUx
#include<stdio.h> typedef unsigned long int uli; typedef uli u; int main() { uli a; u b = -1; a = -1; printf("%lu, %lu", a, b); return 0; }
For 'long int' system will occupy 4 bytes (32 bits).
Therefore,
Binary 1 : 00000000 00000000 00000000 00000001
To represent -1, system uses the 2's complement value of 1. Add 1 to the 1's complement result to obtain 2's complement of 1.
So, First take 1's complement of binary 1 (change all 0s to 1s and all 1s to 0s)
1's complement of Binary 1:
11111111 11111111 11111111 11111110
2's complement of Binary 1: (Add 1 with the above result)
11111111 11111111 11111111 11111111
In HexaDecimal
11111111 11111111 11111111 11111111 = FFFF FFFF FFFF FFFF
In Unsigned Integer
11111111 11111111 11111111 11111111 = 4294967295.
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.