0% found this document useful (0 votes)
3 views2 pages

C Language Programming Concepts

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

C Language Programming Concepts

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Language Notes

■ File Manipulations
#include <stdio.h>

int main() {
FILE *fp;
char name[20];

// Writing to file
fp = fopen("[Link]", "w");
fprintf(fp, "Hello, File Handling!");
fclose(fp);

// Reading from file


fp = fopen("[Link]", "r");
fscanf(fp, "%[^
]", name);
printf("File content: %s", name);
fclose(fp);

return 0;
}

■ Preprocessor Directives
#include <stdio.h>
#define PI 3.14159

int main() {
float r = 5;
float area = PI * r * r;
printf("Area of Circle = %.2f", area);
return 0;
}

■ String Operations
#include <stdio.h>
#include <string.h>

int main() {
char str1[50] = "Hello";
char str2[] = " World";

strcat(str1, str2); // Join strings


printf("Concatenated: %s\n", str1);
printf("Length: %lu\n", strlen(str1));

return 0;
}

■ Math Functions
#include <stdio.h>
#include <math.h>

int main() {
double num = 9.0;
printf("Square Root = %.2f\n", sqrt(num));
printf("2^3 = %.2f\n", pow(2, 3));
printf("Ceil(4.3) = %.2f\n", ceil(4.3));
return 0;
}
■ Enums
#include <stdio.h>

enum Weekday { MON, TUE, WED, THU, FRI, SAT, SUN };

int main() {
enum Weekday today;
today = WED;
printf("Today is Day Number: %d", today); // WED = 2
return 0;
}

■ Unions
#include <stdio.h>

union Data {
int i;
float f;
char str[20];
};

int main() {
union Data data;
data.i = 10;
printf("Integer: %d\n", data.i);

data.f = 220.5;
printf("Float: %.2f\n", data.f); // i is overwritten

return 0;
}

You might also like