Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:31:27+00:00 2026-06-14T23:31:27+00:00

I need to check if an array is empty using macros. If the size

  • 0

I need to check if an array is empty using macros. If the size of array is constant say 2, then I will be able to write a macro like

#define IS_EMPTY(arr)  \
  ((arr[0] | arr[1]) == 0) 

But if arr is defined like this

#define ARRAY_SIZE 100
int arr[ARRAY_SIZE];

Is there any way, a macro can determine that the array is empty? Or is inline functions the only option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:31:28+00:00Added an answer on June 14, 2026 at 11:31 pm

    Your most viable options would be a loop:

    int IsEmpty(char * array, size) {
     int i;
     for (i=0; i<size; i++)
       if (array[i] != 0)
          return 0;
     return 1;
    }
    

    or memcmp:

    int IsEmpty(char * array, size) {
     char * emptyArray = malloc(size);
     memset(emptyArray, 0, size);
     int res = memcmp(array, emptyArray, size);
     free(emptyArray);
    return res==0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check if array contains at least one empty elements. If any
I need to check array value, but when array is empty, I get this:
I just need to check if an array has more than one element. I
I am writing a solution in which I need to check if an array
I need to check the type of each element in an array... for(id obj
I need to check to see if a directory is empty. The problem is,
How to check if javascript variable exist, empty, array, (array but empty), undefined, object
Which is the most reliable way to check if a character array is empty?
I'm using this code, but it returns empty data array. My access_token has all
Using jQuery Multiselect plugin and need to check if any selections have been made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.