ProgrammingHard
int a = 0, b = 0; char op = 0; int n = sscanf("12 + x", "%d %c %d", &a, &op, &b); printf("%d %c", n, op); What is printed?
- A. 2 +
- B. 3 +
- C. 2 x
- D. 1 +
Correct answer: A. 2 +
sscanf converts 12 and then '+', and fails on 'x' for the last %d. It returns the number of successful conversions, 2, and op holds '+'.
More C Programming questions
- Which loop is safe for every value a plain char can hold, including bytes above 127 that may be negative?
- What is the smallest array size that holds the string "Ravi" with strcpy and no undefined behaviour?
- char s[] = "x41x420x43"; printf("%zu", strlen(s)); What is printed?
- char s[] = "banana"; char p = strrchr(s, 'a'); printf("%ld", (long)(p - s)); What is printed?
- printf("%zu", strcspn("aXbYc", "XY") + strspn(" 42ab", " 0123456789")); What is printed?
- A naive strstr-style search looks for a pattern of length m = 50000 in a text of length n = 100000. The text is all 'a' and the pattern is…