Cho mình hỏi 2 vấn đề
- Tại sao trong ảnh người đó chọn tạo trang c++ mà lại viết được chương trình c. Hai cái này khác nhau mà ???
- Tại sao kiểu khai báo là int trong khi c khai báo là void main mà ???
Cho mình hỏi 2 vấn đề
randomq
và visual studio
vàocác thứ bổ sung
. Nói tóm lại, C++ viết code được C nhưng ngược lại thì khôngCho mình hỏi thêm tag randomq ở đâu vậy
Cái hình file kia ghi C++ nhưng mình ghi đuôi gì cũng được. VS có tự động detect xem file là code C hay C++. Bạn vô Project -> Properties -> C/C++ -> Compile as sẽ thấy nó có option cho compile code C hoặc C++
In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined.
C standard (ISO C 9899:1999) bảo là nếu chương trình C ko chạy trên 1 hệ điều hành nào thì giá trị trả về là implementation-defined nghĩa là có thể ko trả về int
A hosted environment need not be provided, but shall conform to the following specifications if present.
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters […] or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared)
còn nếu chạy trên 1 hosted environment nào đó như hệ điều hành Windows thì phải trả về int
(“shall be defined with a return type of int”)
ở đây bạn viết code C chạy trên Windows thì phải trả về int
, còn nếu bạn viết nhúng cho phần cứng nào đó thì tùy, có thể trả về void
Sao nhiều người nghĩ như thế này vậy nhỉ
c++: c plus plus =))))) j/k