can we declare a function inside the structure?
ex: struct book
{
int pages;
float price;
int library(int,float);
}b;
is the above declaration correct? as it has function
declaration?

Answer Posted / vignesh1988i

no , it is not possible in C.. here structure is not a defined class.. so it is not permitted..

in C++ we can use , that is called class , A derived datatype from a structure :)

class class_name
{
ACCESS SPECIFIER : (private/public/protected)
decleration of data member;
member fucntions definitions
{
......
.........
}
};



thank u

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What kind of structure is a house?

755


What is data structure in c and its types?

803


What is volatile variable in c?

852


Explain can you assign a different address to an array tag?

840


What is sizeof array in c?

766


How can my program discover the complete pathname to the executable from which it was invoked?

844


What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }

2248


given post order,in order construct the corresponding binary tree

2530


What are pointers? Why are they used?

841


Describe explain how arrays can be passed to a user defined function

842


Explain how do you determine whether to use a stream function or a low-level function?

827


Explain is it better to bitshift a value than to multiply by 2?

941


Explain the array representation of a binary tree in C.

944


What is meant by preprocessor in c?

730


write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34

1853