educative.io

What is F,f, and * used here?

In below snippet, what is F,f, and *? Never explained earlier!
#include
#include <string.h>

const char* min(const char* s, const char* t){
return (strcmp(s,t) < 0) ? s : t;
}
float min(float x, float y){
return (x < y) ? x : y;
}

int main() {
const char* s = min(“abc”, “xyz”);
float f = min(4.45F, 1.23f);
int f2 = min(2011, 2014);
// float f3 = min(“abc”, 1.23f);

std::cout << s << std::endl;
std::cout << f << std::endl;
std::cout << f2 << std::endl;


Course: https://www.educative.io/courses/cpp-basics
Lesson: https://www.educative.io/courses/cpp-basics/3wPy1r9Lkrr

Hi @Manmay_Barot !!
In the given code snippet:

  • F and f are suffixes used to specify floating-point literals. They indicate that the number is of type float. In C++, F or f is added to the end of a numeric literal to denote that it’s a single-precision floating-point constant. For example, 4.45F and 1.23f are float literals.

  • * is a pointer dereferencing operator. However, in this specific context, it’s being used as part of the string literals "abc" and "xyz". These are string literals, and in C++, they are implicitly treated as const char*. So *s in this context refers to the first character of the string.

So, in summary:

  • F and f: Suffixes indicating single-precision floating-point literals.
  • *: Used as part of string literals to represent the pointer to the first character of the string.
    I hope it helps. Happy Learning :blush: