+ 7

Is it possible to run a program without including the header files? If yes, then how ? And then why to include the header files?

10th Aug 2019, 11:15 AM
Parminder Singh
Parminder Singh - avatar
7 Respuestas
+ 11
Yes it is possible.. but if u want to use methods within the header files then u must include that header file But main() is important don't forget to add that.. Happy learning ☺️.. by the way it is a good question ☺️
10th Aug 2019, 11:26 AM
Sujithra
+ 8
It is possible, if you use the C preprocessor: https://code.sololearn.com/cGyoXq0ebQGz/?ref=app
10th Aug 2019, 11:30 AM
Michael
Michael - avatar
+ 7
We use header files to access predefined library functions.. Suppose if you want to print something on screen with printf() function then you have to include header files <stdio.h> because it is stored in header files ..if you don't want to include header file then you can use std :: . Similarly <conio.h> this header file is used to access functions like clrscr () and getch () . Also we have lots of other header file MATH.H STRING.H you can use it according to your requirement.
12th Aug 2019, 4:36 AM
Ayushi Gujarati
Ayushi Gujarati - avatar
+ 6
the Header files are used to make your programming experience easier For example: you must include <string.h> to use this function strlen("hello world") which calculates the number of characters in the string But you can do that without using this function and including<string.h> You can do that by making your own function as you can see: #include <iostream> using namespace std; int stringlength(string s) {int counter=0; for (int i=0;i>=0;i++) { if(s[i]>='A'&&s[i]<='z'||s[i]==' ') // s[i]=='space' counter ++; else break;} return counter; } int main() { cout<<stringlength ("hello world"); } (I included iostream and used cout because i don't know how to create cout but i think it's something related to classes and these stuff) Or you can just write #include <iostream> #include <string.h> using namespace std; int main() { cout<<strlen("hello world") } And you'll get the same output much easier Hopefully i answered your question
10th Aug 2019, 12:06 PM
Wesam Nabeel
Wesam Nabeel - avatar
+ 6
Sonic extern indicates the compiler that printf has C-linkage.. C links against the standard library by standard and finds a match for the function signature provided so everything works.. In fact if it were a c code you could omit to #include the cstdlib.
11th Aug 2019, 12:16 AM
AZTECCO
AZTECCO - avatar
+ 3
Michael what does extern "C" actually do?
10th Aug 2019, 10:31 PM
Sonic
Sonic - avatar
+ 2
Well I wanna give a good point what header file has is DECLARATIONS of all the important functions you're going to use but it doesn't have the source code for them
12th Aug 2019, 5:08 AM
Zuhail
Zuhail - avatar