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?

Answers were Sorted based on User's Feedback



can we declare a function inside the structure? ex: struct book { int pages; flo..

Answer / srinivasroyal

In CPP the above declaration is correct. But in case of C it
is not.

Is This Answer Correct ?    7 Yes 2 No

can we declare a function inside the structure? ex: struct book { int pages; flo..

Answer / 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

More C Interview Questions

write an interactive program to generate the divisors of a given integer.

7 Answers   TCS,


Explain how can you determine the size of an allocated portion of memory?

0 Answers  


What is openmp in c?

0 Answers  


what is the purpose of the code, and is there any problem with the code? int f( int n, int l, int r ) { return (n << l) >> r; }

2 Answers   Google,


write a program structure to find average of given number

1 Answers  






main() { int i,j,A; for(A=-1;A<=1;A++) prinf("%d\t",!!A); }

6 Answers  


Is reference used in C?

1 Answers  


How can I automatically locate a programs configuration files in the same directory as the executable?

0 Answers  


Is boolean a datatype in c?

0 Answers  


C program to find frequency of each character in a text file?

6 Answers  


What is the use of static variable in c?

0 Answers  


Write a program which take a integer from user and tell whether the given variable is squar of some number or not. eg: is this number is 1,4,9,16... or not

9 Answers   Alcatel,


Categories