Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't comment // on codeblocks

I'm using codeblocks to learn C programming.

When I use /* */ the program works, but when I use // the program returns this error.

expected identifier or ‘(’ before ‘/’ token|

here's the main.c

#include <stdio.h>
#include <stdlib.h>

//Ex1

int i;
float p;
char *n;

int main(void)
{
    i = 22;
    p = 70.0;
    n = "Samuel";

    printf("%s %d %.2f", n, i, p);

    return 0;
}
like image 955
SamuelNLP Avatar asked Jun 16 '26 10:06

SamuelNLP


2 Answers

From wiki:

C++ style line comments start with // and extend to the end of the line. This style of comment originated in BCPL and became valid C syntax in C99; it is not available in the original K&R C nor in ANSI C:

If you use gcc compiler, then add -std=c99 compiler argument. It will enables C99 features, like // comments.

If you have -ansi option, then remove it.

like image 23
SKi Avatar answered Jun 18 '26 00:06

SKi