일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 구글
- nnictl
- 구글클라우드서밋
- 딥러닝
- 구글클라우드플랫폼
- go
- 구글클라우드
- 자격증
- AWS #빅데이터 #분석 #데이터
- Dataproc
- DataFlow
- 구글 클라우드
- 쿠버네티스
- 마이크로서비스
- coursera
- aws
- Associate
- 머신러닝
- docker
- Kubernest
- cloud
- 클라우드
- 클라우드 자격증
- 코세라
- cdk
- 도커
- golang
- 네트워크
- GCP
- Today
- Total
JD의 블로그
[C++ summary ] 본문
Arrays : a collection of similar data elements
The main memory is divided into three sections.
1. Code section
2. Stack
3. Heap
The array will be created inside the stack.
Tht will be directly accessible to the main function.
ex)
int a[5];
[Initializer of array]
int b[5] = {2, 4, 6, 8, 10};
Structures : a collection of data members
Pointer : an address variable stroing address of data
pointer takes sizeof(int) as memory size.
program can directly access "code section" and "stack", but not automatically access heap.
Therefore, heap memory is external to the program.
1.One of the reason of using pointer is accessing heap memory.
if the files are on the hard disk, for accessing a file,be program cannot access this hard disk files directly
because hard disk is external or files are external to a program, so far that, it needs a pointer for accessing and that pointer should be a file.
2.Another main reason to use pointer is accessing the resources which are outside the program like I/O.
3. Parameter passing.
Whenever you declare it will be inside stack.
To get into heap, in C language you have to use malloc().
malloc take the size, how much memory you want to use.
#include <stdlib.h>
int *p;
p= (int *)malloc(5 * sizeof(int)); # the size of memory is decided by the compiler.
malloc() function returns void pointer, so we have to type-caste it
In C++, we have to say "new"
p = new int[5];
Reference (only in C++) : a nickname given to a variable or arraies.
useful in parameter passing
Pointer to Structure
(*p).length = 20;
because higher recedence is for dot operation
or p->length = 20;
Function : a piece of code which performs a specific task
function is a group of related instructions which perform a specific task.
z = add(x. y) -> actual parameter
int add(int a, int b) => formal parameter
Parameter passing method
1. Pass by value (call by value)
2. Call by address : using pointers
3. Call by reference (only in C++)
- References doesn't take any memory!
Array as Parameter
we should also pass what is the size of the array
Arrays can be passed only by address.
int p[] fun(int n) =>it means it is returning an array
int * fun(int n) => this is also possible form
Structure as Parameter
Structures and Functions
The main function is not having any instructions of its own but only calling funtions
Template
Generic functions are template functions
Generic classes are template classes
C++ says that you can use the same class for multiple data types.
so for any type of data it is called as generic class that is defined as a template
template<class T>
class Arithmetic
{
private:
T a;
T b;
public:
Arithmetic(T a , T b);
T add();
T sub();
};
template<class T>
Arithmetic<T>::Arithmetic(T a, T b)
{
this->a=a;
this->b=b;
}
'-프로그래밍 언어 > C++ language' 카테고리의 다른 글
[C++] Code::Blocks - WinMain@16 에러 해결하기 (0) | 2019.08.21 |
---|