当前位置: 首页 > news >正文

C study notes[1]

文章目录

  • the introduction of c language
  • references

the introduction of c language

  1. the first C standard called ANSI C was born in 1983 for the strongly demand of C community,was adopted in 1989,usualy intituled as C89.the C99 standard was constructed starting in 1994 which adds a lot of important and pressing functionalities such as supporting international character sets,allowing to single line notation,new data types,Variable-length array and so on.the standard c00 ommitee’s developing of new C standard began in 2007,released in 2011.however,the C standard always abide by a pricinple that C language is supposed to keep simple and small.
  2. the source code of C will be compilied to an executable which can run on several OS such as windows,linux,unix,macos and so on .
  3. outputing to screen(terminal) is so easy, immediately use the printf function.
#include <stdio.h>
int main(void) {int num = 88;printf("the number is:");printf("%d",num);
}

the first printf fucntion take out the string “the number is:” for outputing to terminal,without line break.the second use two parameters which has one more parameter than the first printf,the newly added parameter is character format and in this example %d represents integer value.there are few formats as similar as %d as follows.

%d 	decimal integer
%f 	floating number
%c 	single char
%s 	string 
%x 	Hexadecimal integer
%p 	pointer address
%% 	Output percentage sign
  • a c program starts its running with main() function,means the main function is the entry of all program .
  • all variables in a C program must be declared earlier than using them.
  1. all variables must belong to a specific data type.
  • basic data types are shown as follows.
int: Integer type, typically 4 bytes (platform-dependent). Range: -2,147,483,648 to 2,147,483,647 (32-bit).char: Character type, 1 byte. Range: -128 to 127 or 0 to 255 (unsigned).float: Single-precision floating-point, 4 bytes. Range: ~1.2E-38 to 3.4E+38.double: Double-precision floating-point, 8 bytes. Range: ~2.3E-308 to 1.7E+308.void: Represents "no type" (used for functions with no return value or pointers to generic data).
  • Type Modifiers

    signed: Allows positive and negative values (default for int and char).

    unsigned: Only non-negative values (doubles the positive range).

    short: Smaller integer (usually 2 bytes). Range: -32,768 to 32,767.

    long: Larger integer (4 or 8 bytes). Range: -2³¹ to 2³¹-1 (32-bit) or -2⁶³ to 2⁶³-1 (64-bit).

    long long: Extended integer (at least 8 bytes). Range: -2⁶³ to 2⁶³-1.

  • Derived Data Types

    Arrays: Contiguous collection of elements of the same type (e.g., int arr[10]).

    Pointers: Stores memory addresses (e.g., int *ptr).

    Structures (struct): Groups variables of different types under one name.

    Unions (union): Similar to struct, but members share memory.

  • User-Defined Types

    typedef: Creates aliases for existing types (e.g., typedef int myInt;).

    Enums (enum): Defines named integer constants (e.g., enum {RED, GREEN, BLUE};).

#include <stdio.h>int main() {int a = 10;float b = 3.14;char c = 'A';double d = 123.456e-10;unsigned long e = 1000000UL;printf("int: %d, float: %f, char: %c, double: %lf, ulong: %lu\n", a, b, c, d, e);return 0;
}
  1. The four operations can be accomplished by mathematical operator
#include <stdio.h>int main() {float num1, num2;char op;printf("请输入两个数字和运算符(如:3 + 5):");scanf("%f %c %f", &num1, &op, &num2);switch (op) {case '+':printf("结果: %.2f\n", num1 + num2);break;case '-':printf("结果: %.2f\n", num1 - num2);break;case '*':printf("结果: %.2f\n", num1 * num2);break;case '/':if (num2 != 0) {printf("结果: %.2f\n", num1 / num2);} else {printf("错误:除数不能为 0!\n");}break;default:printf("错误:无效的运算符!\n");}return 0;
}

of couse,C language already provide a little more complicated computation through math library.

#include <stdio.h>
#include <math.h>int main() {double x = 2.0;printf("e^%.2f = %.2f\n", x, exp(x));      // e^xprintf("2^%.2f = %.2f\n", x, exp2(x));     // 2^xprintf("ln(%.2f) = %.2f\n", x, log(x));    // 自然对数printf("log2(%.2f) = %.2f\n", x, log2(x));  // 以2为底的对数return 0;
}

if you handle more advanced computer knowledge ,so much so that Reverse Polish Expression can be written with C to achieve more tasks.

references

  1. deepseek
http://www.lryc.cn/news/593659.html

相关文章:

  • C语言:20250719笔记
  • CentOS 清理技巧
  • 第二次总结(xss、js原型链)
  • 在开发板tmp目录下传输文件很快的原因和注意事项:重启开发板会清空tmp文件夹,记得复制文件到其他地方命令如下(cp 文件所在路径 文件要复制到的路径—)
  • 【Linux】重生之从零开始学习运维之Nginx之server小实践
  • 定时器中BDTR死区时间和刹车功能配置
  • AWS Partner: Accreditation (Technical)
  • Qt Graphs 模块拟取代 charts 和 data visualization还有很长的路要走
  • SPARKLE:深度剖析强化学习如何提升语言模型推理能力
  • stm32继电器使用方法
  • 【RK3576】【Android14】UART开发调试
  • 从零开始学Tailwind CSS : 颜色配置原理与实践
  • EasyExcel使用
  • 创建套接字并bind的详细过程
  • 深度学习-线性神经网络
  • 深度学习Depth Anything V2神经网络实现单目深度估计系统源码
  • 短视频矩阵的未来前景:机遇无限,挑战并存
  • Maven常用知识总结
  • 代码随想录算法训练营第二十天|回溯part02
  • 电阻耐压参数学习总结
  • 动态规划——数位DP经典题目
  • 【深度学习-Day 38】破解深度网络退化之谜:残差网络(ResNet)核心原理与实战
  • 从0到1搭建一个Rag引擎(ollama+Qwen3)
  • 实现el-select下拉框,下拉时加载数据
  • Docker容器原理和启动策略
  • EP01:【Python 第一弹】基础入门知识
  • aosp15实现SurfaceFlinger的dump输出带上Layer详细信息踩坑笔记
  • 生成式人工智能实战 | 自回归模型详解与实现
  • Linux中添加重定向(Redirection)功能到minishell
  • QGIS和QGC软件的区别