当前位置: 首页 > 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.dtcms.com/a/288420.html

相关文章:

  • LVS技术知识详解(知识点+相关实验部署)
  • simulink系列之模型接口表生成及自动连线脚本
  • 消息队列:数字化通信的高效纽带
  • SQL Server和PostgreSQL填充因子
  • HCIA综合实验
  • string【下】- 内功修炼(搓底层)
  • C++入门--lesson4
  • CCF编程能力等级认证GESP—C++6级—20250628
  • ICT测试原理之--什么是假短
  • 基于opencv的人脸识别考勤系统
  • 人工智能与心理史学:从阿西莫夫的科幻预言到可计算社会模型>
  • Chris Fraser | 中国早期思想中墨家与荀子的知识论
  • 【完整代码】融合时序轨迹与49维特征反演的双色球开奖预测模型:一项关于隐藏规律的探索
  • Maven常用知识总结
  • Docker容器原理和启动策略
  • 传统浏览器过时了?Dia如何用AI重新定义上网体验
  • 零基础学习性能测试第二章-linux服务器监控:内存监控
  • 【60】MFC入门到精通——运行后 button按键上不显示 按键名, 控件上的文字不显示
  • 阶段1--Linux存储管理
  • Codeforces Round 1037(Div3)
  • 【web安全】万能密码
  • 车载诊断架构 --- OEM对于DTC相关参数得定义
  • 计算机网络1.1:计算机网络在信息时代的作用
  • 教你如何借助AI精读文献
  • python基础笔记
  • LRU算法及优化
  • 佛经个人阅读(一)《心经》解析
  • 纸板制造糊机操作
  • 数据类型选择:存储销量与查询性能的平衡
  • yolov8-pos/yolov11-pos openvino C++部署