hi


i have problem i have to devolpe a program ,that can't use a printf ,but i have to display a string.

is this works


int a = printf("How is this\n");
main()
{
int b;
}

This will work in C++ wht abt c?

AND one more HOW sizeof()
implemented in C means Sourrce code ?

Recommended Answers

All 5 Replies

>This will work in C++ wht abt c?
No, it won't work in either because you can't call a function at global scope. It also fails to meet the requirements because you try to use printf. :icon_rolleyes:

>HOW sizeof() implemented in C means Sourrce code?
You can't do it portably. That's why C has a sizeof operator.

Can you use putchar() and display each character one at a time?

cin and cout?

you cant call a function outside main(),

in c++ you can use cout to output data, that requires iostream.h so if you feel you want to use that in c, copy the header file to c's directory.

when you're thinking you can use string functions, you're wrong, string functions require printf or puts to output data..actually, we always use that functions in c.

now, how will you output data without using those functions?

well, you must create one, you can edit or create header files, ..
by that, you create a function that outputs data, and name it your way...

In c++, just use cout..

goodluck!!

>This will work in C++ wht abt c?
No, it won't work in either because you can't call a function at global scope....

calling a function at global scope is certainly possible in C++. dynamic initialization of statics at global scope is supported; here caling printf to initialize a global integer is no different from calling the constructor to initialize std::cout.

if you cannot use formatted output functions like printf, fprintf etc., an fwrite (unformatted output) is a possibility. fwrite returns a size_t, so you can still use it for dynamic initialization of a global int.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.