Sep 17, 2024
main
function.#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
printf
function is used to print output to the console.int age;
double gpa;
char grade;
int
: Integer numbers.double
: Decimal numbers.char
: Single characters.char[]
is used for strings (e.g., arrays of characters).if (condition) {
// code to execute if true
} else {
// code to execute if false
}
switch (variable) {
case value1:
// code
break;
case value2:
// code
break;
default:
// code
}
while (condition) {
// code to execute
}
for (initialization; condition; increment) {
// code to execute
}
returnType functionName(parameters) {
// code
return value;
}
struct Student {
char name[50];
int age;
double gpa;
};
int *ptr;
printf("%d", *ptr);
fopen
, fprintf
, and fgets
.r
: Readw
: Write (overwrites existing files)a
: Append (adds to end of file)FILE *fp;
fp = fopen("file.txt", "w");
fprintf(fp, "Hello, World!");
fclose(fp);
FILE *fp;
fp = fopen("file.txt", "r");
fgets(line, sizeof(line), fp);
fclose(fp);