Sponsored Links

Interview Questions



INTERVIEW QUESTIONS C ARRAYS IN C DETAILS

Question: Can the sizeof operator be used to tell the size of an array passed to a function?


Answer: No. There’s no way to tell, at runtime, how many elements are in an array parameter just by looking at the
array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to
the first element.

Category Arrays in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.3) By 8575 users
Added on 7/19/2011
Views 69970
Rate it!

Question: Can the sizeof operator be used to tell the size of an array passed to a function?




Answer:

No. There’s no way to tell, at runtime, how many elements are in an array parameter just by looking at the
array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to
the first element. Source: CoolInterview.com


In VC++, this is wat i tried

main()
{
int a[10];
printf("%d", sizeof(a);
}

Output: 40

This shows dat the sizeof can be operated on arrays as well. Source: CoolInterview.com

Answered by: Datta | Date: | Contact Datta Contact Datta

20 Source: CoolInterview.com

Answered by: hemasundar | Date: | Contact hemasundar Contact hemasundar

yes Source: CoolInterview.com

Answered by: hemasundar | Date: | Contact hemasundar Contact hemasundar

yes Source: CoolInterview.com

Answered by: hemasundar | Date: | Contact hemasundar Contact hemasundar

GOD!!!! so many 'yes'...

The answer is NO.. Pass the array element to a function and see. The array is passed as a pointer (pointer to the begining address of the array).. Source: CoolInterview.com

Answered by: Vivek | Date: | Contact Vivek Contact Vivek

no,size of operator is compile time operator, it is used for determine the lenght of array and structure but in compile time not run time Source: CoolInterview.com

Answered by: VICKY SHRIVASTVA | Date: 12/9/2009 | Contact VICKY SHRIVASTVA Contact VICKY SHRIVASTVA

sizeof() is an operator, it is not a function, this is reason you are getting the answer out at 40.

Try the following:

# include <stdio.h>
# include <malloc.h>

void printf_sz(int a[])
{
printf("
Sizeof : %d", sizeof(a));
}



main()
{
int a[20];

printf ("
Sizeof : %d", sizeof(a));

printf_sz(a);


}

The output of the above program is 80 and 4.

Check for yourself
Source: CoolInterview.com

Answered by: Deoashish Dane | Date: 12/22/2009 | Contact Deoashish Dane Contact Deoashish Dane

Yes, there is a way -

#include<conio.h>
#include<stdio.h>

int main()
{
int arr[] = {4, 2, 4, 5, 2, 3, 1};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf("Array size = %d", arr_size);
getchar();
return 0;
} Source: CoolInterview.com

Answered by: Manan | Date: 6/19/2010 | Contact Manan Contact Manan

hey we can not calculate size of the array element we can only calculate the size of the datatype only try this
headerfile
void main()
{
clrscr();
int i;
printf("the size of i is ",size of (i));
getch();
} Source: CoolInterview.com

Answered by: PARTHIBAN.V | Date: 7/21/2010 | Contact PARTHIBAN.V Contact PARTHIBAN.V

No,It is not possible ..

#include<stdio.h>
#include<conio.h>

void sourav(int a[])
{

int p=sizeof(a);
printf("%d",p);

}


int main()
{

int a[10];
sourav(a);

getch();
return 0;
}

This program gives output 4.But it is not correct ,so it is not possible. Source: CoolInterview.com

Answered by: sourav | Date: 7/27/2010 | Contact sourav Contact sourav

how about useing the strlen() instead of size of it'll do more favout Source: CoolInterview.com

Answered by: erwer | Date: 7/30/2010 | Contact erwer Contact erwer

we can know about the no. of elements in an array by the help of "sizeof()" operator if and only if we know the data type and the total bytes hold by that array... Source: CoolInterview.com

Answered by: shashi kant pal | Date: 8/7/2010 | Contact shashi kant pal Contact shashi kant pal

yo shd do practicaly n clear here yo r not goin to get any thng Source: CoolInterview.com

Answered by: saurav | Date: 8/29/2010 | Contact saurav Contact saurav

#include<stdio.h>
#include<conio.h>

void main()
{

long int a[10];
clrscr();
printf("%d", sizeof(a));
getch();
}
output: 20,in case of char output is 10
hey we can calculate size of the array element.which depends on the datatype only try this Source: CoolInterview.com

Answered by: jayant kumar | Date: 9/3/2010 | Contact jayant kumar Contact jayant kumar


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
How to remove duplicate elements from an array

View Answer
How can you sort the elements of the array in descending order?
View Answer
Array is an lvalue or not?
View Answer
Can the size of an array be declared at runtime?
View Answer
Can the sizeof operator be used to tell the size of an array passed to a function?
View Answer
Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
View Answer
When does the compiler not implicitly generate the address of the first element of an array?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Arrays in C Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2025 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions