Delphi

『Cプログラマのための C++入門』

『Cプログラマのための C++入門』 柴田望洋『Cプログラマのための C++入門』を勉強してまいります。 1. C++ に慣れよう 1-1-1 コメント 1-1-2 定数 1-2-1 関数プロトタイプ 1-2-2 可変個引数 1-2-3 デフォルト引数 1-2-4 インライン引数 1-3-1 Cリンケージと…

メンバへのポインタ

Cプログラマのための C++入門 > 2.クラスの概念 > メンバへのポインタ C++ #include <stdio.h> #include "Student.h"int main(int argc, char* argv[]) { Student Shibata("柴田望洋", 180, 80); Student Masuyan("増田真二", 170, 60); Shibata.Print(); Masuyan.Pri</stdio.h>…

コンストラクタ

Cプログラマのための C++入門 > 2.クラスの概念 > コンストラクタ C++ #include <stdio.h> #include "Student.h"void PrintStudent(Student x) { printf("%s\n", x.Name()); printf(" 英語 = %d\n", x.English()); printf(" 数学 = %d\n", x.Mathematics()); printf("</stdio.h>…

this ポインタ

Cプログラマのための C++入門 > 2.クラスの概念 > this ポインタ C++ #include <stdio.h>struct student { public: char name[20]; int eng; int math; private: int ave; public: void calc_ave(); int average(); };void student::calc_ave() { this->ave = (this-></stdio.h>…

メンバ関数

Cプログラマのための C++入門 > 2.クラスの概念 > メンバ関数 C++ #include <stdio.h>struct student { public: char name[20]; int eng; int math; private: int ave; public: void calc_ave(); int average(); };void student::calc_ave() { ave = (eng + math) / 2</stdio.h>…

構造体とメンバの透過性

Cプログラマのための C++入門 > 2.クラスの概念 > 構造体とメンバの透過性 C++ #include <stdio.h>struct student { char name[20]; int eng; int math; int ave; };void calc_ave(student* x) { x->ave = (x->eng + x->math) / 2; }int average(student* x) { return</stdio.h>…

関数の多重定義

Cプログラマのための C++入門 > 1. C++ に慣れよう > 関数の多重定義 C++ #include <stdio.h>int abs(int x) { return (x < 0 ? -x : x); } long abs(long x) { return (x < 0L ? -x : x); } double abs(double x) { return (x < 0.0 ? -x : x); }int main(int argc, </stdio.h>…

『明解C言語 入門編』in multi language

『明解C言語 入門編』in multi language 柴田望洋『明解C言語 入門編』を勉強してまいります。 1. まずは慣れよう 000.整数値 15 と 37 の和を表示する 001.整数値 15 から 37 を引いた値を表示する 002.整数値 15 と 37 の和を親切に表示する 003.2つの変…

ポインタのソート

明解C言語 入門編 > 12. 構造体 > ポインタのソート C #include <stdio.h> #include <string.h> #include <alloc.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;typedef int (*compare)(gstudent*, gstudent*);int compare_height(gstudent* </alloc.h></string.h></stdio.h>…

構造体の動的配列 (realloc)

明解C言語 入門編 > 12. 構造体 > 構造体の動的配列 (realloc) C #include <stdio.h> #include <string.h> #include <alloc.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;typedef int (*compare)(gstudent*, gstudent*);int compare_height(</alloc.h></string.h></stdio.h>…

構造体の動的配列 (malloc)

明解C言語 入門編 > 12. 構造体 > 構造体の動的配列 (malloc) C #include <stdio.h> #include <string.h> #include <alloc.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;typedef int (*compare)(gstudent*, gstudent*);int compare_height(g</alloc.h></string.h></stdio.h>…

5人の学生を 身長・体重で ソート (関数ポインタ)

明解C言語 入門編 > 12. 構造体 > 5人の学生を 身長・体重で ソート (関数ポインタ) C #include <stdio.h> #include <string.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;typedef int (*compare)(gstudent*, gstudent*);int comp</string.h></stdio.h>…

5人の学生を 身長で ソート (構造体)

明解C言語 入門編 > 12. 構造体 > 5人の学生を 身長で ソート (構造体) C #include <stdio.h> #include <string.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;void swap(gstudent* x, gstudent* y) { gstudent tmp = *x; *x = *y;</string.h></stdio.h>…

構造体を返す関数

明解C言語 入門編 > 12. 構造体 > 構造体を返す関数 C #include <stdio.h> #include <string.h>typedef struct { char name[20]; int height; float weight; } gstudent;gstudent hiroko(char name[], int height, float weight) { gstudent tmp; strcpy(tmp.name, name); tmp.</string.h></stdio.h>…

構造体の受け渡し

明解C言語 入門編 > 12. 構造体 > 構造体の受け渡し C #include <stdio.h> #include <string.h>struct gstudent { char name[20]; int height; float weight; };void hiroko(struct gstudent* std) { (*std).height = 180; (*std).weight = 80; }int main(int argc, char* argv</string.h></stdio.h>…

構造体のメンバの初期化

明解C言語 入門編 > 12. 構造体 > 構造体のメンバの初期化 C #include <stdio.h> #include <string.h>struct gstudent { char name[20]; int height; float weight; };int main(int argc, char* argv[]) { struct gstudent sanaka = {"Sanaka", 175, 60.5}; printf("氏名:%s\n</string.h></stdio.h>…

構造体

明解C言語 入門編 > 12. 構造体 > 構造体 C #include <stdio.h> #include <string.h>struct gstudent { char name[20]; int height; float weight; };int main(int argc, char* argv[]) { struct gstudent sanaka; strcpy(sanaka.name, "Sanaka"); sanaka.height = 175; sanaka</string.h></stdio.h>…

5人の学生を 身長で ソート (配列)

明解C言語 入門編 > 12. 構造体 > 5人の学生を 身長で ソート (配列) C #include <stdio.h> #include <string.h>#define NINSU 5void swap(int* x, int* y) { int tmp = *x; *x = *y; *y = tmp; }void swaps(char sx[], char sy[]) { char tmp[256]; strcpy(tmp, sx); strcpy(</string.h></stdio.h>…

5人の学生の身長を ソート

明解C言語 入門編 > 12. 構造体 > 5人の学生の身長を ソート C #include <stdio.h>#define NINSU 5void swap(int* x, int* y) { int tmp = *x; *x = *y; *y = tmp; }void sort(int data[], int n) { int k = n - 1; while (k >= 0) { int i, j; for (i = 1, j = -1;</stdio.h>…

さまざまな文字列操作

明解C言語 入門編 > 11. 文字列とポインタ > さまざまな文字列操作 C #include <stdio.h> #include <string.h>int main(int argc, char* argv[]) { /* strcat */ char st1[100] = "1234567890"; char st2[100] = "ABCDE"; printf("%s + ", st1); printf("%s = ", st2); strcat(</string.h></stdio.h>…

指定した文字数だけ、文字列をコピー

明解C言語 入門編 > 11. 文字列とポインタ > 指定した文字数だけ、文字列をコピー C #include <stdio.h> #include <string.h>char* str_ncpy(char* d, const char* s, size_t n) { char* t = d; int j = 1; unsigned i; for (i = 0; i < n; i++) { if ((*s) && j) *d++ = *s++;</string.h></stdio.h>…

文字列のコピー

明解C言語 入門編 > 11. 文字列とポインタ > 文字列のコピー C #include <stdio.h> #include <string.h>char* str_cpy(char* d, const char* s) { char* t = d; while (*d++ = *s++) ; return t; }int main(int argc, char* argv[]) { int i; char* st1 = "12345"; char* st2 =</string.h></stdio.h>…

文字列の長さを調べる

明解C言語 入門編 > 11. 文字列とポインタ > 文字列の長さを調べる C #include <stdio.h> #include <string.h>unsigned str_length(const char* str) { size_t len = 0; while (*str++) len++; return len; }int main(int argc, char* argv[]) { char str[100] = "ABC"; printf</string.h></stdio.h>…

「配列で実現する文字列」の配列と、「ポインタで実現する文字列」の配列

明解C言語 入門編 > 11. 文字列とポインタ > 「配列で実現する文字列」の配列と、「ポインタで実現する文字列」の配列 C #include <stdio.h>int main(int argc, char* argv[]) { char str[3][6] = {"Turbo", "NA", "DOHC"}; char* ptr[3] = {"12345", "67", "890A"};</stdio.h>…

配列で実現する文字列と、ポインタで実現する文字列との、違い (文字列の代入)

明解C言語 入門編 > 11. 文字列とポインタ > 配列で実現する文字列と、ポインタで実現する文字列との、違い (文字列の代入) C #include <stdio.h>int main(int argc, char* argv[]) { char str[] = "ABC"; char* ptr = "123"; str = "123"; /* これは、エラー */ ptr</stdio.h>…

配列で実現する文字列と、ポインタで実現する文字列との、共通点

明解C言語 入門編 > 11. 文字列とポインタ > 配列で実現する文字列と、ポインタで実現する文字列との、共通点 C #include <stdio.h>int main(int argc, char* argv[]) { char str[] = "ABC"; char* ptr = "123"; int i; for (i = 0; str[i]; i++) putchar(str[i]); p</stdio.h>…

配列で実現する文字列と、ポインタで実現する文字列

明解C言語 入門編 > 11. 文字列とポインタ > 配列で実現する文字列と、ポインタで実現する文字列 C #include <stdio.h>int main(int argc, char* argv[]) { char str[] = "ABC"; char* ptr = "123"; printf("str = \"%s\"\n", str); printf("ptr = \"%s\"\n", ptr); </stdio.h>…

配列の受け渡し

明解C言語 入門編 > 10. ポインタ > 配列の受け渡し C #include <stdio.h>#define NINSU 5void int_set(int* vc, int no) { int i; for (i = 0; i < no; i++) vc[i] = i; }int main(int argc, char* argv[]) { int i = NINSU; int j; int ary[NINSU] = {0}; printf("</stdio.h>…

配列とポインタ

明解C言語 入門編 > 10. ポインタ > 配列とポインタ C #include <stdio.h>int main(int argc, char* argv[]) { int i; int vc[] = {10, 20, 30, 40, 50}; int* ptr = &vc[0]; for (i = 0; i < 5; i++) { printf("vc[%d] = %d " , i, vc[i]); printf("ptr[%d] = %d " </stdio.h>…

2つの値を交換する

明解C言語 入門編 > 10. ポインタ > 2つの値を交換する C #include <stdio.h>void swap1(int nx, int ny) { int tmp = nx; nx = ny; ny = tmp; }void swap2(int* nx, int* ny) { int tmp = *nx; *nx = *ny; *ny = tmp; }int main(int argc, char* argv[]) { int na </stdio.h>…