Plz answer my these C doubts-
Q. 1- If i have 3 source files and i declare a static variable in the source file s2.c then which statement is true:-
That static variable is created when the program starts executing and is destroyed when the whole program finishes executing.
OR
That static variable is created when the source file s2.c starts executing and is destroyed when the file s2.c finishes executing.
(I dont want to know abt the scope of the static variable)

Q. 2- Header contains the declarations of functions & variables and in C it is not necessary(even though its safer) to give a prototype of a function before its use in the program. So does it mean that if we dont include a header file which declares a function X(), even then we can use that function(bcoz the header file contains only the prototype of the function, which is not necessary in C).

Q. 3- What do the .obj and .lib files contain?

Recommended Answers

All 11 Replies

Q1: Alternative 1
Q2: If the function X returns an integer, uses standard calling convention (and possibly is not dynamically linked, I'm not sure about the actual meaning of __declarespec(import)).
Q3: .obj is most oftenly compiled code, all functions and variables from a compiled source file. .lib I think contains either multiple such object files in a kind of archive, or link information for dynamic linkage (thought I'm not quite sure of this since it mostly just work for me).

>Plz answer my these C doubts-
"Doubt" is sometimes synonymous with "question", but not in this case. It's very common to ignorantly use doubt in place of question, and it's usually wrong. What you have a C questions, not C doubts.

>I dont want to know abt the scope of the static variable
Obviously, since your question has nothing to do with scope and everything to do with storage duration. There's no need to qualify your question as such because if someone starts talking about scope, you know that they're not qualified to answer it correctly. :)

>in C it is not necessary(even though its safer) to give a
>prototype of a function before its use in the program.
Wrong on two counts. First, the latest C standard removed that dangerous feature. Second, even in C89, the implicit function declaration doesn't always work depending on the arguments and return value of the function in question.

>What do the .obj and .lib files contain?
It depends heavily on the compiler and linker in question. The generic answer is that object files contain object code, which is the primary output of the compiler. The linker then uses the object code to piece together an executable file. Library files are basically independent collections of object code and links.

Plz answer my these C doubts-
Q. 1- If i have 3 source files and i declare a static variable in the source file s2.c then which statement is true:-
That static variable is created when the program starts executing and is destroyed when the whole program finishes executing.
OR
That static variable is created when the source file s2.c starts executing and is destroyed when the file s2.c finishes executing.
(I dont want to know abt the scope of the static variable)

[IMG]http://www.daniweb.com/techtalkforums/dani-images/icons/solution.gif[/IMG]A)second statement is true

Q. 2- Header contains the declarations of functions & variables and in C it is not necessary(even though its safer) to give a prototype of a function before its use in the program. So does it mean that if we dont include a header file which declares a function X(), even then we can use that function(bcoz the header file contains only the prototype of the function, which is not necessary in C).

[IMG]http://www.daniweb.com/techtalkforums/dani-images/icons/solution.gif[/IMG]A)function prototype is necessary only in C++ as its one of the syntax that u should give function definion b4 u use it in main() as function prototype.
In C its not needed 2 declare the prototype of a function.
The answer 4 ur question is yes if u r working with a c compiler.

Q. 3- What do the .obj and .lib files contain?

[IMG]http://www.daniweb.com/techtalkforums/dani-images/icons/solution.gif[/IMG]A) .obj and .lib are the files with extension obj and lib.

.obj refer to the files related to have object code contained in them.
.lib refer to files related to library functions.

>Plz answer my these C doubts-
"Doubt" is sometimes synonymous with "question", but not in this case. It's very common to ignorantly use doubt in place of question, and it's usually wrong. What you have a C questions, not C doubts.

I think this is something taught in India. The only posters that have 'doubts' seem to be from there...

#include<iostream.h>
#include<conio.h>
int &maxref(int &a, int &b)
{
if (a>b)
return a;
else
return b;
}
void main()
{
int x=20,y=30, max=0;
clrscr();
maxref(y,y)=-1;
cout<<"\n value of x is :"<<x;
cout<<"\n value of y is :"<<y;
getch();
}

This program output is
value of xis 20
value of y is : -1
but how to get this output?
help me.

commented: You're kidding, right? Don't hijack a thread. -1

#include<iostream.h>
#include<conio.h>
void main()
{
int x[5]={5,2,3,4,5}, y[5]={1,4,3,2,1};
int result[5]={0,0,0,0,0};
int i=0;
clrscr();
while(i++<5)
result=x-y;
cout<<"\n The contents of the array are:\n";
i=0;
do
{
cout<<'\t'<<x<<'\t'<<y<<'\t'<<result<<'\n';
i++;
}
while(i<5);
getch();
}
Q:
How to work this program ? Help me.

int a=1;
printf("%d%d%d",a,++a,a++);

the doubt is the output is not 122
its 331.can any one explain it

Hi first you need to study operator precedence well. Here you are using ++ operator post fix and prefix. ++ directly charge the value in variable address.

post fix (a++)- print first and increment
perfix (++a)- increment first and print the value

printf("%a%a%a", a, ++a, a++);
                          1    //and then increment  a = 2;
printf("%a%a%a", a, ++a, a++);
                      3    1    //its prefix so increment a = 3 an print
printf("%a%a%a", a, ++a, a++);
                  3    3    1 

Hi first you need to study operator precedence well. Here you are using ++ operator post fix and prefix. ++ directly charge the value in variable address.

post fix (a++)- print first and increment
prefix (++a)- increment first and print the value

printf("%a%a%a", a, ++a, a++);
                          1    //and then increment  a = 2;
printf("%a%a%a", a, ++a, a++);
                      3    1    //its prefix so increment a = 3 an print
printf("%a%a%a", a, ++a, a++);
                  3    3    1

end quote.

First you need to study side effects and sequence points. The snippet exhibits undefined behavior, which means that the output can be anything at all. Further, the output isn't even required to be consistent. You can run the program twice and completely different results should be expected with undefined behavior.

This thread has become a wealth of bad examples...

commented: Finally some sense in this thread. :D (Even if it is 5 years old) +1
void main()
{
int x=4,i;
i=fun(x=x/4);
printf("%d",i);
}
int fun(int c)
{
return c/2;
}

the answer is 1...how??please reply ....

will c pgm act as back end?
if it acts what will be the front end

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.