954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Doubts in C

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?

akshayabc
Newbie Poster
15 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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).

perniciosus
Junior Poster in Training
78 posts since Nov 2005
Reputation Points: 29
Solved Threads: 4
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
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.

see2penc
Newbie Poster
1 post since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
>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. Theonly posters that have 'doubts' seem to be from there...

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

#include
#include
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 :"<

raja.mdu
Newbie Poster
2 posts since Jun 2010
Reputation Points: 9
Solved Threads: 0
 

#include
#include
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[i]=x[i]-y[i];
cout<<"\n The contents of the array are:\n";
i=0;
do
{
cout<<'\t'<

raja.mdu
Newbie Poster
2 posts since Jun 2010
Reputation Points: 9
Solved Threads: 0
 

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

reddy55
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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
[CODE][
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
/CODE]

ganesh_IT
Light Poster
39 posts since Jul 2010
Reputation Points: 10
Solved Threads: 2
 

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 [CODE][ 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 /CODE]


Firstyou 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...

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
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 ....

soumya.ranjan
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

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

gayathri balu
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You