Example:
#include <stdio.h>
#include <string.h>
int main()
{
char str[30] = "12345678910111213";
printf("The last position of '2' is %d.\n",
strrchr(str, '2') - str);
return 0;
}
Output: The last position of '2' is 14.
/* Prints a random number in the range 0 to 99 */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
randomize();
printf("Random number in the 0-99 range: %d\n", random (100));
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
#include<stdio.h> #include<string.h> int main() { char dest[] = {97, 97, 0}; char src[] = "aaa"; int i; if((i = memcmp(dest, src, 2))==0) printf("Got it"); else printf("Missed"); return 0; }
if((i = memcmp(dest, src, 2))==0) When comparing the array dest and src as unsigned chars, the first 2 bytes are same in both variables.so memcmp returns '0'.
Then, the if(0=0) condition is satisfied. Hence the output is "Got it".
#include<stdio.h> int main() { int i; i = scanf("%d %d", &i, &i); printf("%d\n", i); return 0; }
printf("%d\n", i); Here it prints 2.
Copyright ©CuriousTab. All rights reserved.