error: ‘_Atomic’ does not name a type

#include <stdio.h>
#include <stdatomic.h>

int main() {
    _Atomic int x = 5;
    printf("Value of x: %d\n", x);
    return 0;
}

Explanation:

  1. #include <stdio.h>: Includes the standard input-output header file for functions like printf.

  2. #include <stdatomic.h>: Includes the standard atomic operations header file, which is required for using atomic types and operations.

  3. int main() {: Starts the main function.

  4. _Atomic int x = 5;: Declares an atomic integer variable named x and initializes it with the value 5. The _Atomic keyword is used to indicate that x is an atomic variable.

  5. printf("Value of x: %d\n", x);: Prints the value of the atomic variable x using the %d format specifier.

  6. return 0;: Indicates successful completion of the program.

  7. }: Closes the main function.