getmaxyx - Linux


getmaxyx() is a useful command that retrieves the maximum values for both the x-axis and y-axis of the currently active screen window. It plays a vital role in determining the size and dimensions of the terminal window, making it an indispensable utility for developers and anyone working with terminal-based applications.


getmaxyx(WINDOW *win, int *y, int *x)


  • win: Pointer to the window object.
  • y: Reference to an integer variable to store the maximum y-axis value.
  • x: Reference to an integer variable to store the maximum x-axis value.




Basic Usage

#include <ncurses.h>
WINDOW *win;
int y, x;
getmaxyx(win, &y, &x);

Resize Aware Application

while (1) {
  getmaxyx(stdscr, &y, &x);
  // Update application based on new size information

Common Issues

Inaccurate Output

Ensure that the win parameter points to a valid window object. Otherwise, it may provide incorrect values.

Output Limitations

getmaxyx() only provides information about the current active window. If your application manages multiple windows, you need to query each window individually.


getmaxyx() integrates well with other ncurses functions, including:

  • getmaxy() and getmaxx(): Retrieve the maximum values for the y-axis and x-axis, respectively.
  • resizeterm(): Alter the size of the terminal window.

Related Commands

  • clear(): Clears the screen.
  • printw(): Prints formatted text to the screen.
  • refresh(): Updates the contents of the screen.