debut d01 ex03

This commit is contained in:
hugogogo
2022-02-05 19:14:56 +01:00
parent e6929e8e12
commit c1990815e2
11 changed files with 306 additions and 0 deletions

61
d01/ex02/Makefile Normal file
View File

@@ -0,0 +1,61 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . name = value . name is case sensitive #
# VARIABLES . or name = value \ . use VPATH only for .c #
# . value . or .cpp #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
NAME = brain
CC = clang++
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 -g3
VPATH = $(D_SRCS)
LIBS =
INCLUDES = -I$(D_HEADERS)
D_SRCS = .
SRCS = main.cpp
D_HEADERS = .
HEADERS =
D_OBJS = builds
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
RM_D_OBJS = rm -rf $(D_OBJS)
ifeq "$(D_OBJS)" "."
RM_D_OBJS =
endif
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . target: prerequisites . $@ : target #
# RULES . recipe . $< : 1st prerequisite #
# . recipe . $^ : all prerequisites #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: $(NAME)
$(D_OBJS)/%.o: %.cpp | $(D_OBJS)
$(CC) $(CFLAGS) -c $< -o $@
$(D_OBJS):
mkdir $@
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
$(NAME): $(OBJS)
$(CC) $(OBJS) -o $@ $(LIBS)
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
$(RM_D_OBJS)
re: fclean all
.PHONY : all clean fclean re bonus run valgrind

BIN
d01/ex02/brain Executable file

Binary file not shown.

26
d01/ex02/main.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include <iostream>
#include <string>
int main(void)
{
std::string brain = "HI THIS IS BRAIN";
std::string * stringPTR = &brain;
std::string & stringREF = brain;
// • Ladresse de la string en mémoire.
// • Ladresse stockée dans stringPTR.
// • Ladresse stockée dans stringREF.
// Puis :
// • La valeur de la string.
// • La valeur pointée par stringPTR.
// • La valeur pointée par stringREF.
std::cout << &brain << std::endl;
std::cout << stringPTR << std::endl;
std::cout << &stringREF << std::endl << std::endl;
std::cout << brain << std::endl;
std::cout << *stringPTR << std::endl;
std::cout << stringREF << std::endl;
return (0);
}