24.07.31

day2

1.基础知识

1.1 计算机结构

冯 诺依曼结构

在这里插入图片描述

1.2 什么是程序

广义上讲,为了实现一个特定的目标而预先设计的一组可操作的工作步骤,称之为一个程序。

    
程序就是系统可以识别的一组有序的指令。存储在磁盘上,被加载到内存中执行。

1.3 数据

定义:送入计算机的数字,字母,符号等信息必须转换成01组合的数据形式才能被计算机接收、存储并进行运算
    
    
能够进行算术运算得到明确数值概念的信息成为计算机数值数据,其余的信息成为非数值数据
   
1.3.1 数值数据
进制
 
十进制   0~9
八进制   0~7                                0开头
二进制   01  
十六进制  0~9 a、b、c、d、e、f                0x开头
    
 
    
 
/*****************进制之间的转换********************/    
其他进制转十进制
    (1)位权表达式

    
十进制转二进制:
    1711)短除法
    (2)凑方法

    
八进制转二进制:一位换三位
   074    
   111 100
    
十六进制转二进制:一为换四位
   0xaf
   1010  1111 

    
二进制转八进制:三位换一位
   0111 1010
   001  111   010
     1    7      2
    0172
    
二进制转十六进制:四位换一位  
    0111 1010
    7      a
    0x7a   
1.3.2非数值数据
字符数据  ASCII
    
'a'  'b'  '1'    
1.4C语言的框架
#include <stdio.h>
int  main()
{
	   	


		return 0;
}

1.5词法符号

1.5.1关键字
关键字是由系统预定义的词法符号,有特定的含义,不允许用户重新定义
    
    
auto  break  case  char  const    continue      default  do   double   else    enum     extern             float        for        goto    if          int       long     register        return    short            signed             sizeof          static           struct    switch          typedef           union          unsigned      void    volatile        while    
    
    
所有关键字均为小写    
1.5.2标识符
标识符是由程序员按照命名规则自行定义的词法符号,用于定义宏名、变量名、函数名和自定义类型名等
    
C语言的命名规则如下:
    1) 标识符由一个或多个字母、数字或下划线组成
    2)标识符的第一个字符必须是字母或下划线
    3)标识符不能与任何关键字相同

大小写敏感;  ab  Ab  aB AB
命名有一定含义,便于记忆,增加可读性    
1.5.3分隔符
分隔符是用来分隔其他的词法符号,主要包括: 
             空格符、制表符(tab)、换行符号、注释
     通过对分隔符的恰当运用,使得代码的外观格式更为清晰易读,还可以帮助分析程序中的语法错误

                 
                 
//  注释一行
                 
/* 
	代码块              ---- 注释一段代码

*/            
1.5.4运算符
算术运算符
 + - * /  %       
逻辑运算符
&&  ||  !
    
 
    
逻辑与  &&: 全真为真, 有假就假
  表达式1  &&  表达式2  
    真           真             真   
    真           假             假  
    假           真             假
    假           假             假
    
    
   
逻辑或 ||:有真就真,全假为假
     表达式1  ||  表达式2 
      真           真           真
      真           假           真
      假           真           真 
      假           假           假
    
    
逻辑非
    
    !(表达式)
    
    若果表达式为真,整体为假
              假       真
    
    
短路法则:
    	逻辑与, 如果第一个表达式为假,那么后一个表达式不需要判断(也不会执行表达式),整体为假
        逻辑或, 如果第一个表达式为真,那么后一个表达式不需要判断(也不会执行表达式),整体为真
    
关系运算符
>  <  <=  >=  ==  !=
    
真:1(非零为真)   
假:0       
    
关系运算符的结果 只有 01    
位运算符
  &  |  ~  >>   <<
        
位运算是二进制位的运算      

C语言存的都是补码   正数:三码合一    负数:有区别
把最高位作为符号位   0:正数   1:负数
      
      

7
0000 0111
      
-7
1000 0111      
      
      
原码:最高位符号位,其余位数值位    
7
0000 0111
      
-7
1000 0111       
       
反码:符号位不变,其余位取反
7
0000 0111
      
-7
1111 1000      
      
补码 :反码基础上 + 1      
7
0000 0111
      
-7
1111 1001        
      
       
补码转原码:
      (1)逆推法
      (2)补码的补码就是原码 
      
      
位与&1&1=1  1&0=0  0&1=0  0&0=0

    5 & 3 = 1
    -5 & 3 = 3   
     
位或|1|1=1  1|0=1  0|1=1   0|0=0  
 
      
位取反~:
     ~1 = 0    ~0 = 1
         
         
         
>>n 右移n位    :右边移出去,左补符号位         
正数:
10 >> 2        
0000 1010    0000 0010     
         
负数: 
-13
1000 1101 
1111 0010
1111 0011  >> 3    
1111 1110
1000 0001
1000 0010    
       
15   >>  4
-23  >>  2    
         
<<n 左移n位 :  左边移动出去,右边补0
    
正数:    
0000 0111  << 2    
0001 1100
    
负数:
-1
1000 0001
1111 1110
1111 1111   << 3
1111 1000    
1000 0111
1000 1000   
    
    
    
作用:
        
char a = 10;     0000 1010  
a = 8;           0000 1000

    
***************************************清零***************************************
  0000 10101位清零          ? &  0 = 0
& 1111 1101&  1 =1         0000 0001  
  1 << 1    0000 0010
  ~         1111 1101 
    
 char a = 10; 
 a = a &  (~(1 << 1))
     
     
  & 0000 10101位和第3位清零    
    1111 0101 
     
 a = a & (~(1 << 1  |  1 << 3))    
 a &= (~(1 << 1  |  1 << 3));  


***************************************置位(1)***************************************
char a = 10;     0000 1010    把第 5 位置1| 0 =  ?   
                                                   ? | 1 = 1
   0000 1010    
 | 0010 0000
    
  a = a | (1 << 5);


char a = 10;     0000 1010    把第 57 位置1 
    
a = a | (1 << 5 | 1 << 7) 
    
    
   1111 1010    5~7 置成 101 
  &1000 1111
   1000 1010
  |0101 0000
   1101 1010    
赋值运算符
=  把等号右边的值,赋值给等号的左边   

注意:等号的左值不能为一个常量    
    
    
复合赋值
    +=     a+=10   -->  a = a + 10;
    -=
    *=
    /=

eg:
	int a = 2;
    a += 20 *20;    // a = a + (20 * 20);		
递增递减运算符
++  --
    
(1)++ -- 独立成一句
    
    前++ 等价与 后++----

(2)在运算式中    
    
   前++--: 先进行自加(自减)运算,运算后的结果作为整体的值
   后++--: 先取值作为整体的值,再进行自加(自减)运算
地址运算符
&  取地址
逗号运算符
int a;
a=102030;   每一个式子都会执行
    
    
最后一个式子的结果作为整体的值
    
a = (a + 10, 60, 100 + 30);   



eg:
	int a;
    int x = 10, y = 20; 
    a = (x = 20, y + 1 , x + y); 

    printf("%d\n", a); 
sizeof运算符
用于计算数据类型的大小    --- 结果是数据类型的大小  单位为字节
    
一个字节  --- 8位二进制数  
1024b = 1kb
1024kb = 1mb 
1024mb = 1gb                    
1024gb = 1Tb       
    
1GB =  2^3 * 2^10   * 2^10  * 2^10  = 2^33 
    
    
sizeof(int)
三目运算符
表达式1 ? 表达式2 : 表达式3	

如果表达式1为真,则执行表达2,
           假,        3 


    
三目运算符用于简单的判断,复杂的用if else   switch case    
1.5.5标点符号
C语言中的标点符号有逗号、分号、冒号、花括号、圆括号。

1.6 打印调试

1.6.1 宏定义
#define  宏名  替换内容           ---宏名一般大写


eg:
    #define  N 10 + 10
    
    printf("%d\n", N*N);    10 + 10 * 10 + 10  ...  120
    
    
 作用:
    (1)便于修改
    (2)提高阅读性
1.6.2 打印调试的宏


 printf("%s,%s,%d\n",__FILE__,__FUNCTION__,__LINE__);

1.7数据类型

char   		字符型        1字节         无符号:0~255   有符号:-128~127  
short  		短整型        2字节
int    		整型          4字节    
long        长整型         8字节
long long   长长整型       8字节
float       单精度浮点型    4字节         5~6double      双精度浮点型    8字节         15~16char   c1= 128;       //出错,数据越界(-128)
char   c1= 129;       //出错,数据越界(-127)
unsigned char  c2= -1;  //出错,数据越界(255)
    
 
short  a = 32768; 
  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DHCP(动态主机配置协议)是一种自动分配IP地址和其他网络配置信息的协议。在Linux系统中,DHCP服务器通常使用dhcpd服务来提供这种服务。配置dhcpd服务需要编辑dhcpd.conf文件。下面是一个基本的dhcpd.conf配置示例: ``` # option definitions common to all supported networks option domain-name "example.com"; option domain-name-servers ns1.example.com, ns2.example.com; default-lease-time 600; max-lease-time 7200; # Use this to enble / disable dynamic dns updates globally. #ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. subnet 192.168.1.0 netmask 255.255.255.0 { } # This is a very basic subnet declaration. subnet 10.254.239.0 netmask 255.255.255.224 { range 10.254.239.10 10.254.239.20; option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; } # This declaration allows BOOTP clients to get dynamic addresses, # which we don't really recommend. #subnet 10.254.239.32 netmask 255.255.255.224 { # range dynamic-bootp 10.254.239.40 10.254.239.60; # option broadcast-address 10.254.239.31; # option routers rtr-239-32-1.example.org; #} # A slightly different configuration for an internal subnet. #subnet 10.5.5.0 netmask 255.255.255.224 { # range 10.5.5.26 10.5.5.30; # option domain-name-servers ns1.internal.example.org; # option domain-name "internal.example.org"; # option routers 10.5.5.1; # option broadcast-address 10.5.5.31; # default-lease-time 600; # max-lease-time 7200; #} # Hosts which require special configuration options can be listed in # host statements. If no address is specified, the address will be # assigned from the declared subnet. The addresses for the hosts # must be in the declared subnet. #host passacaglia { # hardware ethernet 0:0:c0:5d:bd:95; # filename "vmunix.passacaglia"; # server-name "toccata.fugue.com"; #} # Fixed IP addresses can also be specified for hosts. These addresses # should not also be listed as being available for dynamic assignment. # Hosts for which fixed IP addresses have been specified can boot using # BOOTP or DHCP. Hosts for which no fixed address is specified can only # be booted with DHCP, unless there is an address range on the subnet # to which a BOOTP client is connected which has the dynamic-bootp flag # set. #host fantasia { # hardware ethernet 08:00:07:26:c0:a5; # fixed-address fantasia.fugue.com; #} # You can declare a class of clients and then do address allocation # based on that. The example below shows a case where all clients # in a certain class get addresses on the 10.17.224/24 subnet, and all # other clients get addresses on the 10.0.29/24 subnet. #class "foo" { # match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; #} #shared-network 224-29 { # subnet 10.17.224.0 netmask 255.255.255.0 { # option routers rtr-224.example.org; # } # subnet 10.0.29.0 netmask 255.255.255.0 { # option routers rtr-29.example.org; # } # pool { # allow members of "foo"; # range 10.17.224.10 10.17.224.250; # } # pool { # deny members of "foo"; # range 10.0.29.10 10.0.29.230; # } #} ``` 在上面的示例中,定义了三个子网:192.168.1.0/24,10.254.239.0/27和10.5.5.0/27。每个子网都有自己的IP地址范围,路由器和其他网络配置选项。如果需要,可以添加更多的子网和其他选项。请确保在编辑配置文件之前备份原始文件,并在更改配置后重启dhcpd服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值