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

  • SEARCH
  • Home
  • 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 5945431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:40:50+00:00 2026-05-22T16:40:50+00:00

Here is my code: int main(void) { int i; Coords** latLng; Quadrado* q1; latLng[0]

  • 0

Here is my code:

int main(void)
{
    int i;
    Coords** latLng;
    Quadrado* q1;
    latLng[0] = AdicionaValores(latLng[0],-23.000490,-43.346687);
    latLng[1] = AdicionaValores(latLng[1],-22.988243,-43.342224);
    q1 = AdicionaValoresQuadrado(q1,-23.000490,-43.346687,-22.988243,-43.342224);

    printf("# Connecting to database.\n");
    for(i=0;i<2;i++)
    {
    if(clientInside(q1, latLng[i]))
        printf("Dentro");
    else
        printf("Fora");
    }
    system("PAUSE");
}

Here is AdicionaValores and AdicionaValoresQuadrado:

Coords* AdicionaValores(Coords* v, double x, double y)
{
    v = (Coords*) malloc(sizeof(Coords));
    v->x = x;
    v->y = y;
    return v;
}

Quadrado* AdicionaValoresQuadrado(Quadrado* q, double x1, double y1, double x2, double y2)
{
    q = (Quadrado*) malloc(sizeof(Quadrado));
    q->x1 = x1;
    q->x2 = x2;
    q->y1 = y1;
    q->y2 = y2;
    return q;
}

it compiles just fine with 2 warnings, telling me that latLng and q1 are uninitialized! what should I do ?? malloc them on main ? help!

  • 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-05-22T16:40:50+00:00Added an answer on May 22, 2026 at 4:40 pm

    latLng and q1 are indeed uninitialized.

    Coords** latLng;
    latLng[0] = …
    

    You’ve never assigned anything to latLng, and yet you try to treat it as a pointer to an array where you want to put a value. You need not only to initialize latLng to a valid pointer, but also allocate memory for the array. Since this is an array with a fixed size (2) which doesn’t need to last beyond the lifetime of the function, you can allocate it on the stack.

    Coords* latLng[2];
    latLng[0] = …
    

    After that change, you’ll still get warnings about uninitialized variables, but this is due to a problem in the interface of AdicionaValores and AdicionaValoresQuadrado. These functions never actually use their first argument, but they require one, and you’re passing a completely arbitrary value. Just remove the first argument, and declare v as a local variable.

    Coords* AdicionaValores(double x, double y)
    {
        Coords *v = malloc(sizeof(Coords));
        v->x = x;
        v->y = y;
        return v;
    }
    

    (Note that you don’t need to cast the return value of malloc, and you should never use a cast unless you have a reason to and you understand why. In a production program, you should check if malloc runs out of memory, but that’s ok for now.) Then in main:

    Coords* latLng[2];
    Quadrado* q1;
    latLng[0] = AdicionaValores(-23.000490,-43.346687);
    latLng[1] = AdicionaValores(-22.988243,-43.342224);
    q1 = AdicionaValoresQuadrado(-23.000490,-43.346687,-22.988243,-43.342224);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
Here is my code!(sorry for my poor english) #include<stdio.h> int convert(char ch); int main(void)
Consider this snippet of code: void do_child(void); int main(void){ int n; pid_t child; printf(Write
Here is my code: #include <stdio.h> #include <unistd.h> static volatile int t=0; int main(void){
I'm trying to write a video using opencv's VideoWriter. Here's code: int main() {
I got an EXC_BAD_ACCESS in main() , here is my code: int main(int argc,
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
I am trying to read file by following code void main() { int i=0;
here is my code for(int i = 0; i < number ; i++) {
Here is code example class A{ int i; public: A(int i) : i(i) {}

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.