Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
struct List {
int val;
struct List* next;
};
struct List* head;
@BMuscle
BMuscle / point7.cpp
Created October 13, 2019 03:51
ポインタ説明7
#include <stdio.h>
void func1(int &b) {
b = 10;
}
int main()
{
int a = 50;
func1(a);
@BMuscle
BMuscle / point6.cpp
Created October 13, 2019 03:19
ポインタ説明6
#include <stdio.h>
#include <stdlib.h>
int *func1() {//このような書き方はしてはならない。 aが保証されないため
int a = 10;
return &a;
}
int *func2() {//これはmallocで確保しているので自動変数の領域には入らない
int *a = (int*)malloc(sizeof(int) * 10);
#include <stdio.h>
void func1() {
printf("関数func1が呼ばれました\n");
}
void func2() {
printf("関数func2が呼ばれました\n");
}
@BMuscle
BMuscle / point4.cpp
Created October 13, 2019 01:35
ポインタ説明4
#include <stdio.h>
int main()
{
int a[10]; //int型の配列10個分 a宣言
char* p; //char型ポインタp宣言
p = (char*)a; //a[0]のアドレスをpに格納
//forで0-9まで格納していく
for (int i = 0; i < 10; i++) {
@BMuscle
BMuscle / point3.cpp
Last active October 12, 2019 13:40
ポインタ説明3
#include <stdio.h>
#include <malloc.h>
int global;
static int stglobal;
void func1() {
int local = 0;
printf("ローカル変数func1=%p\n", (void*)&local);
}
@BMuscle
BMuscle / point2.cpp
Created October 12, 2019 12:07
ポインタ説明2
#include <stdio.h>
int main()
{
int a[10]; //int型の配列10個分 a宣言
int b; //int型 b宣言
int *p; //int型ポインタp宣言
p = &b; //bのアドレスをpに格納
//forで0-9まで格納していく
@BMuscle
BMuscle / point.cpp
Last active October 12, 2019 12:08
ポインタ説明1
#include <stdio.h>
int main()
{
int a; //int型変数aを宣言
int* p; //int型のポインタpを宣言
p = &a; //aのアドレスをpに格納
a = 10; //aへ10を格納
@BMuscle
BMuscle / janken.cpp
Last active August 29, 2019 13:26
じゃんけんソース⑥
#include <stdio.h>
int jankenJudge(int p1, int p2) {//プレイヤーの手を引数に
int judge;//返す為のjudgeを宣言
//勝ち負けの判定
if (p1 == p2) {
judge = 3;//あいこの場合
}
else {
p1 = p1 % 3;//相手との差を求める
@BMuscle
BMuscle / janken.cpp
Last active August 29, 2019 12:44
じゃんけんソース⑤
#include <stdio.h>
int jankenJudge(int p1, int p2){//プレイヤーの手を引数に
int judge;//返す為のjudgeを宣言
//勝ち負けの判定
if(p1 == p2){
judge = 3;//あいこの場合
}else{
p1 = p1 % 3;//相手との差を求める
if(p1 + 1 == p2){