code.club

 找回密碼
 立即註冊
搜索
123
返回列表 發新帖
樓主: enter
打印 上一主題 下一主題

基本重要觀念筆記

[複製鏈接]
地板
 樓主| 發表於 2015-7-2 18:56:25 | 只看該作者
#include <stdio.h>
#include <stdlib.h>

void test(int *);

int main(void){

int x=123;
int *p=&x;

test(p); //這裡是傳入x的位址,p=&x

        return 0;
       
       
}

void test(int *j) //這裡*j表示要傳入指標所代表的位址
{
       
        printf("%d",*j); //這裡*j則是表示指標代表位址的那個值
       
}
回復 支持 反對

使用道具 舉報

板凳
 樓主| 發表於 2015-6-5 01:08:50 | 只看該作者
#include <stdio.h>
#include <stdlib.h>

int main(void){
       
        char ch;
        printf("input a character:");
        scanf(" %c",&ch); //在%c之前留一空格,則scanf會略過輸入的空白格而取第一個出現的字符。否則若按空白鍵就會被直接scanf去。
        printf("%c",ch);
       
        return 0;
       
                 }
回復 支持 反對

使用道具 舉報

沙發
發表於 2015-6-3 00:00:05 | 只看該作者
本帖最後由 return 於 2015-6-3 00:31 編輯

#include <stdio.h>
#include <stdlib.h>

int main(void){
        printf("%d\n",sizeof(char));// 1
        printf("%d\n",sizeof('k'));// 4, 因為將'k'先變為ASKII碼的數字,故視為 int
        printf("%d\n",sizeof(2)); // 4
        printf("%d\n",sizeof(int)); // 4
        printf("%d\n",sizeof(long)); // 8
        printf("%d\n",sizeof(2L)); // 8, 2是常數但給予 long 型態
        printf("%d\n",sizeof(float)); // 4
        printf("%d\n",sizeof(2.3f)); // 4
        printf("%d\n",sizeof(2.3));        // 8, 後面不特別標明是float則有小數點一律給予 double 型態
        printf("%4.2f\n",23.456);// 五捨六入
        printf("%4.2f\n",23.455);// 五捨六入
        printf("%3.2f, %3.2f, %3.2f\n",1.234, 1.235, 1.236); // 四捨五入
        printf("%3.2f, %3.2f, %3.2f\n",1.244, 1.245, 1.246); // 四捨五入
        printf("%3.2f, %3.2f, %3.2f\n",1.254, 1.255, 1.256); // 五捨六入

                return 0;
        }
回復 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|手機版|Archiver|code.club  

GMT+8, 2024-5-19 03:03 , Processed in 0.061070 second(s), 14 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表